如何跳过node.js中的asynchronous调用

有什么方法可以跳过串行或并行呼叫stream程中的呼叫。

var flow = require('flow'); flow.exec( function(){ //Execute }, function(){ //Skip }, function(){ //Exec }, function(){ //Done } ); 

只需在您可能想跳过的方法内创build一个条件,并立即触发callback

 flow.exec( function taskOne() { // long task fs.readFile(path, 'utf8', this); }, function taskTwo() { if (condition) { return this(); // trigger the callback. } }, function lastTask() { console.log("done"); } ); 
 function getUser(userId,username,callback){ flow.exec( function(){ if(userId) return this(null,userId); redis.get('username:'+username,this); }, function(err,userId){ if(err) throw err; if(!userId) return callback(null); this.userId = userId; redis.hgetall('user:'+userId+':profile',this); }, function(err,profile){ if(err) throw err; profile.userId = this.userId; callback(profile); } ); } getUser(null,'gk',function(user){ if(!user) console.log('not found'); console.log(user); }); 

我可以这样使用吗?