Skip to content

Commit

Permalink
simplify waterfall, add test for arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
aearly committed Jul 1, 2018
1 parent 9952cf7 commit c063c6b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
5 changes: 1 addition & 4 deletions lib/waterfall.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ export default function(tasks, callback) {
}

function next(err/*, ...args*/) {
if (err === false || canceled) {
canceled = true
return
}
if (err === false) return
if (err || taskIndex === tasks.length) {
return callback.apply(null, arguments);
}
Expand Down
22 changes: 22 additions & 0 deletions test/eachOf.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,28 @@ describe("eachOf", function() {
}, 20);
});


it('forEachOfLimit canceled (async, array)', function(done) {
var obj = ['a', 'b', 'c', 'd', 'e'];
var call_order = [];

async.eachOfLimit(obj, 3, function(value, key, callback){
call_order.push(key, value);
setTimeout(() => {
if (value === 'b') {
return callback(false);
}
callback()
})
}, function(){
throw new Error('should not get here')
});
setTimeout(() => {
expect(call_order).to.eql([ 0, "a", 1, "b", 2, "c", 3, "d" ]);
done()
}, 20);
});

it('forEachOfLimit canceled (async, w/ error)', function(done) {
var obj = { a: 1, b: 2, c: 3, d: 4, e: 5 };
var call_order = [];
Expand Down
2 changes: 1 addition & 1 deletion test/forever.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('forever', function(){
setTimeout(() => {
expect(counter).to.eql(2)
done()
})
}, 10)
})
});
});

0 comments on commit c063c6b

Please sign in to comment.