summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Early <aearly@fluid.com>2016-01-07 15:19:31 -0800
committerAlexander Early <aearly@fluid.com>2016-01-07 15:19:31 -0800
commite99cb6a46482955585c8b749c7bffe3476499244 (patch)
treed8b454aa9c55afd4116028847727d53e2e3d5bbc
parentf8cea478196657170e829c4205b88ed3ef36cc09 (diff)
downloadasync-e99cb6a46482955585c8b749c7bffe3476499244.tar.gz
document promise support for asyncify. #956
-rw-r--r--README.md26
1 files changed, 26 insertions, 0 deletions
diff --git a/README.md b/README.md
index b9f20e3..316c405 100644
--- a/README.md
+++ b/README.md
@@ -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" />