diff options
author | Alexander Early <alexander.early@gmail.com> | 2018-09-03 00:04:05 -0700 |
---|---|---|
committer | Alexander Early <alexander.early@gmail.com> | 2018-09-03 00:04:05 -0700 |
commit | 31e68c3f7ea7c1afe6425379edc16ae088780674 (patch) | |
tree | 67996e8f15a0d9a060110bfdc033df2645822700 | |
parent | 105fd5d2bd08dbd5c3f29a695b76a18cb159f0d7 (diff) | |
download | async-31e68c3f7ea7c1afe6425379edc16ae088780674.tar.gz |
awaitable waterfall (lol)
-rw-r--r-- | lib/waterfall.js | 8 | ||||
-rw-r--r-- | test/es2017/awaitableFunctions.js | 12 |
2 files changed, 17 insertions, 3 deletions
diff --git a/lib/waterfall.js b/lib/waterfall.js index f4c3ddc..f9a6c24 100644 --- a/lib/waterfall.js +++ b/lib/waterfall.js @@ -1,8 +1,8 @@ -import noop from './internal/noop'; import once from './internal/once'; import onlyOnce from './internal/onlyOnce'; import wrapAsync from './internal/wrapAsync'; +import awaitify from './internal/awaitify' /** * Runs the `tasks` array of functions in series, each passing their results to @@ -61,8 +61,8 @@ import wrapAsync from './internal/wrapAsync'; * callback(null, 'done'); * } */ -export default function(tasks, callback) { - callback = once(callback || noop); +function waterfall (tasks, callback) { + callback = once(callback); if (!Array.isArray(tasks)) return callback(new Error('First argument to waterfall must be an array of functions')); if (!tasks.length) return callback(); var taskIndex = 0; @@ -82,3 +82,5 @@ export default function(tasks, callback) { nextTask([]); } + +export default awaitify(waterfall) diff --git a/test/es2017/awaitableFunctions.js b/test/es2017/awaitableFunctions.js index b0b3bda..e226187 100644 --- a/test/es2017/awaitableFunctions.js +++ b/test/es2017/awaitableFunctions.js @@ -558,4 +558,16 @@ module.exports = function () { ], 2) expect(calls).to.eql([1, 2, 3]) }); + + it('should return a Promise: waterfall', async () => { + expect (async.waterfall.name).to.contain('waterfall') + const calls = [] + await async.waterfall([ + async () => { await Promise.resolve(); calls.push(1) }, + async () => { await Promise.resolve(); calls.push(2) }, + async () => { await Promise.resolve(); calls.push(3) }, + async () => { await Promise.resolve(); calls.push(4) }, + ], 2) + expect(calls).to.eql([1, 2, 3, 4]) + }); }; |