diff options
author | Alexander Early <aearly@fluid.com> | 2016-01-07 15:19:31 -0800 |
---|---|---|
committer | Alexander Early <aearly@fluid.com> | 2016-01-07 15:19:31 -0800 |
commit | e99cb6a46482955585c8b749c7bffe3476499244 (patch) | |
tree | d8b454aa9c55afd4116028847727d53e2e3d5bbc | |
parent | f8cea478196657170e829c4205b88ed3ef36cc09 (diff) | |
download | async-e99cb6a46482955585c8b749c7bffe3476499244.tar.gz |
document promise support for asyncify. #956
-rw-r--r-- | README.md | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -1783,6 +1783,32 @@ async.waterfall([ ], callback) ``` +If the function passed to `asyncify` returns a Promise, that promises's resolved/rejected state will be used to call the callback, rather than simply the synchronous return value. Example: + +```js +async.waterfall([ + async.apply(fs.readFile, filename, "utf8"), + async.asyncify(function (contents) { + return db.model.create(contents); + }), + function (model, next) { + // `model` is the instantiated model object. + // If there was an error, this function would be skipped. + } +], callback) +``` + +This also means you can asyncify ES2016 `async` functions. + +```js +var q = async.queue(async.asyncify(async function (file) { + var intermediateStep = await processFile(file); + return await somePromise(intermediateStep) +})); + +q.push(files); +``` + --------------------------------------- <a name="log" /> |