A async.waterfall is nested within a async.forEachOfLimit loop as shown in the code below.
Question: How do you skip an iteration of async.forEachLimit when the code is executing a step inside async.waterfall? In other words, break out of async.waterfall and back into async.forEachLimit. I have commented the location in the code where this check should occur
The current code gives an error Callback was already called.
Also, if i use a return callback() in place of cb() when I want to break out of async.waterfall, no error occurs but it is not skipped.
var async = require('async')
var users = ['a','b','c']
async.forEachOfLimit(users, 1, function(user, index, cb) {
console.log(index + ': ' + user)
async.waterfall([
function(callback) {
callback(null);
},
function(callback) {
// Skip async.forEAchOfLimit iteration when index == 1
if(index == 1)
cb()
callback(null);
}
], function (err, result) {
console.log(index + ": done")
cb()
});
}, function() {
console.log('ALL done')
})
Error
0: a
0: done
1: b
2: c
1: done
/Users/x/test/node_modules/async/lib/async.js:43
if (fn === null) throw new Error("Callback was already called.");
^
Error: Callback was already called.
Desired Output
0: a
0: done
1: b
2: c
2: done
ALL done
Using return callback()
var async = require('async')
var users = ['a','b','c']
async.forEachOfLimit(users, 1, function(user, index, cb) {
console.log(index + ': ' + user)
async.waterfall([
function(callback) {
callback(null);
},
function(callback) {
// Skip async.forEAchOfLimit iteration when index == 1
if(index == 1)
return callback()
callback(null);
}
], function (err, result) {
console.log(index + ": done")
cb()
});
}, function() {
console.log('ALL done')
})
Output
Doesn't break out...
0: a
0: done
1: b
1: done
2: c
2: done
ALL done
breakin a normal loop?