如何摆脱async.each循环内的asynchronous系列 – node.js

我需要跳过一个async.series的函数或突破,并想知道我应该如何去做。 我有一系列需要迭代的项目。 我把这个列表放在一个async.each函数中。 然后,数组中的每个项目在进行之前都会经过一系列所需的function(在下一个中需要一个信息)。 但是在某些情况下,我只需要通过第一个函数,如果不满足条件(例如,它是一个我们不使用的类),则callback到下一个项目的async.each循环。 这是我的代码的一个例子:

exports.process_items = function(req, res, next){ var user = res.locals.user; var system = res.locals.system; var likes = JSON.parse(res.locals.likes); var thecat; //process each item async.each(items, function(item, callback){ //with each item, run a series of functions on it... thecat = item.category; async.series([ //Get the category based on the ID from the DB... function(callback) { //do stuff callback(); }, //before running other functions, is it an approved category? //if it is not an approved category, SKIP THE OTHER FUNCTIONS IN THE LIST (but how?) function(callback) { //do stuff callback(); }, //some other functionality run on that item, function(callback){ //do stuff callback(): } ], function(err) { if (err) return next(err); console.log("done with series of functions, next item in the list please"); }); //for each like callback... callback(); }, function(err){ //no errors }); } 

将退出快捷方式放在依赖函数的顶部。 例如:

 async.series([ //Get the category based on the ID from the DB... function(callback) { //do stuff callback(); }, //before running other functions, is it an approved category? //if it is not an approved category, SKIP THE OTHER FUNCTIONS IN THE LIST (but how?) function(callback, results) { if (results[0] is not an approved category) return callback(); //do stuff callback(); },