Skip to content

Commit e99cb6a

Browse files
author
Alexander Early
committed
document promise support for asyncify. #956
1 parent f8cea47 commit e99cb6a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

README.md

+26
Original file line numberDiff line numberDiff line change
@@ -1783,6 +1783,32 @@ async.waterfall([
17831783
], callback)
17841784
```
17851785
1786+
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:
1787+
1788+
```js
1789+
async.waterfall([
1790+
async.apply(fs.readFile, filename, "utf8"),
1791+
async.asyncify(function (contents) {
1792+
return db.model.create(contents);
1793+
}),
1794+
function (model, next) {
1795+
// `model` is the instantiated model object.
1796+
// If there was an error, this function would be skipped.
1797+
}
1798+
], callback)
1799+
```
1800+
1801+
This also means you can asyncify ES2016 `async` functions.
1802+
1803+
```js
1804+
var q = async.queue(async.asyncify(async function (file) {
1805+
var intermediateStep = await processFile(file);
1806+
return await somePromise(intermediateStep)
1807+
}));
1808+
1809+
q.push(files);
1810+
```
1811+
17861812
---------------------------------------
17871813
17881814
<a name="log" />

0 commit comments

Comments
 (0)