async.series

async.series

  async.series

  series适用于顺序执行异步且前后无关联的调用。对于顺序执行异步且前后有叛逆的调用,则需要使用waterfall

  If any functions in the series pass an error to its callback, no more functions are run, andcallback is immediately called with the value of the error. Otherwise, callback receives an array of results when tasks have completed.

  

async.series([
function(callback) {
// do some stuff ...
callback(null, 'one');
},
function(callback) {
// do some more stuff ...
callback(null, 'two');
}
],
// optional callback
function(err, results) {
// results is now equal to ['one', 'two']
}); async.series({
one: function(callback) {
setTimeout(function() {
callback(null, 1);
}, 200);
},
two: function(callback){
setTimeout(function() {
callback(null, 2);
}, 100);
}
}, function(err, results) {
// results is now equal to: {one: 1, two: 2}
});

参考:https://caolan.github.io/async/docs.html#series

上一篇:编写一个void sort(int*x,int n)实现将x数组中的n个数据从大到小排序。n及数组元素在主函数中输入。将结果显示在屏幕上并输出到文件


下一篇:《TensorFlow技术解析与实战》——1.2 什么是深度学习