install
Async
bower install async
npm install async
jam install async
spm install async
component install caolan/async
.waterfall
async.waterfall([
function(callback) {
getUserById(userId, function(user) {
callback(null, user);
});
},
function(user, callback) {
getDepartmentByUser(user.id, function(department) {
callback(null, department);
});
},
function(department, callback) {
getUserById(department.id, function(users) {
console.log(users)
callback(null);
});
}
])
parallel
async.parallel([
function(callback) {
getUsers(function(users) {
callback(null, users);
});
},
function(callback) {
getDepartments(function(departments) {
callback(null, departments);
});
},
function(callback) {
getTasks(function(tasks) {
callback(null, tasks);
});
}
], function(err, results) {
console.log(results);
});
series
async.series([
function(callback) {
if (...) {
code1();
callback(null);
} else {
code2();
callback(null);
}
},
function(callback) {
getUsers();
}
])
评论
发表评论