forked from freewind/async_demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
var async = require('async'); | ||
|
||
var t = require('./t'); | ||
var log = t.log; | ||
|
||
/** | ||
* async.apply是一个非常好用的函数,可以让我们给一个函数预绑定多个参数并生成一个可直接调用的新函数,简化代码。 | ||
* | ||
* function(callback) { t.inc(3, callback); } | ||
* 等价于: | ||
* async.apply(t.inc, 3); | ||
*/ | ||
async.parallel([ | ||
async.apply(t.inc, 3), | ||
async.apply(t.fire, 100) | ||
], function (err, results) { | ||
log('err: ', err); | ||
log('results: ', results); | ||
}); | ||
|
||
// 预设参数 | ||
var x = async.apply(t.inc, 1); | ||
x(function(err, n){ | ||
console.log('1.inc: ' + n); | ||
}); |