0
我有一组函数,我需要以同步方式执行(在完成之后,我使用前一个函数的结果调用另一个函数)。每个函数都以字典为参数。 是否有任何模块已经完成node.js或JavaScript?异步执行的函数队列
我有一组函数,我需要以同步方式执行(在完成之后,我使用前一个函数的结果调用另一个函数)。每个函数都以字典为参数。 是否有任何模块已经完成node.js或JavaScript?异步执行的函数队列
您可以使用ES5 Array.reduce
:
function queueFunctions(funcs, initialValue, commonData) {
funcs.reduce(function(previousValue, currentValue/*, index, array*/){
return currentValue(previousValue, commonData);
}, initialValue);
}
例如:
queueFunctions([prompt, confirm, alert], 'foo?');
https://github.com/kriskowal/q,https://github.com/caolan/async –