AsyncJS 指的是 async,是一个异步处理的组件。
Series 和 Limit 的区别
Series - the same as but runs only a single async operation at a time Limit - the same as but runs a maximum of limit async operations at a time
async.map
1 | var names = ['James', 'Kobe', 'Havard', 'Jermmy', 'Rondo']; |
输出:
1 | [ 'JAMES', 'KOBE', 'HAVARD', 'JERMMY', 'RONDO' ] |
async. each
1 | async.each(names, function(name, callback) { |
输出:
1 | James |
async.eachSeries
1 | async.eachSeries(names, function(name, callback) { |
输出:
1 | James |
async.parallel
1 | async.parallel([function(callback) { |
输出:
1 | yy |
async.waterfall
1 | async.waterfall([function(callback) { |
输出:
1 | yy |
async.filterLimit
1 | async.filterLimit(names, 2, function(name, callback) { |
输出:
1 | [ 'James' ] |
async.reject
1 | async.reject(names, function(name, callback) { |
输出:
1 | [ 'Kobe', 'Havard', 'Jermmy', 'Rondo' ] |
async.reduce
1 | async.reduce([1, 2, 3, 4], 0, function(memo, num, callback) { |
输出:
1 | 10 |
async.every
1 | async.every(names, function(name, callback) { |
输出:
1 | true |
async.auto
1 | async.auto({ |
输出:
1 | in get_data |