diff options
author | Alex Early <alexander.early@gmail.com> | 2018-09-30 17:00:10 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-30 17:00:10 -0700 |
commit | 8aecf108b3922bc5211036706a0f6f75e02bd42b (patch) | |
tree | 0f7b6bee315231ef4aefdfbee154822921de231f /lib/auto.js | |
parent | df41256f49c9bb3126e035c95aca7860329b6acf (diff) | |
download | async-8aecf108b3922bc5211036706a0f6f75e02bd42b.tar.gz |
feat: await-able Async methods (#1572)
* make each and family awaitable
* dont pretend they're AsyncFunctions
* check errors
* ensure function name is preserved somehow
* awaitable concat
* awaitable detect
* awaitable every/filter
* awaitable groupBy
* awaitable map/mapValues
* awaitable reduce
* awaitable reject
* awaitable some
* awaitable transform
* awaitable times
* awaitable auto
* awaitable compose/seq
* awaitable whilst/until (lol)
* awaitable forever
* awaitable parallel/race
* awaitable retry
* awaitable series (lol)
* awaitable tryEach
* awaitable waterfall (lol)
* lint
* cleanup, remove noop and unused internal functions
Diffstat (limited to 'lib/auto.js')
-rw-r--r-- | lib/auto.js | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/lib/auto.js b/lib/auto.js index b06e3c5..ad92d74 100644 --- a/lib/auto.js +++ b/lib/auto.js @@ -1,8 +1,7 @@ -import noop from './internal/noop'; - import once from './internal/once'; import onlyOnce from './internal/onlyOnce'; import wrapAsync from './internal/wrapAsync'; +import { promiseCallback, PROMISE_SYMBOL } from './internal/promiseCallback' /** * Determines the best order for running the {@link AsyncFunction}s in `tasks`, based on @@ -42,7 +41,7 @@ import wrapAsync from './internal/wrapAsync'; * pass an error to their callback. Results are always returned; however, if an * error occurs, no further `tasks` will be performed, and the results object * will only contain partial results. Invoked with (err, results). - * @returns undefined + * @returns {Promise} a promise, if a callback is not passed * @example * * async.auto({ @@ -83,13 +82,13 @@ import wrapAsync from './internal/wrapAsync'; * console.log('results = ', results); * }); */ -export default function (tasks, concurrency, callback) { - if (typeof concurrency === 'function') { +export default function auto(tasks, concurrency, callback) { + if (typeof concurrency !== 'number') { // concurrency is optional, shift the args. callback = concurrency; concurrency = null; } - callback = once(callback || noop); + callback = once(callback || promiseCallback()); var numTasks = Object.keys(tasks).length; if (!numTasks) { return callback(null); @@ -251,4 +250,6 @@ export default function (tasks, concurrency, callback) { }); return result; } + + return callback[PROMISE_SYMBOL] } |