Await promises in a pull-stream.
pull(
pull.values([ 'hello', Promise.resolve('world') ]),
await, // use pull-await on promises or anything thenable.
pull.collect(function(err, res) {
t.same(res, ['hello', 'world']);
})
);
$ npm install --save pull-await
Pull promises, thenable objects, or regular through and await those necessary.
await(function(err, cb) {
// Push promises to read for `await`
cb(null, new Promise(r => setTimeout(() => r('hello'), 1000)));
cb(null, Promise.resolve('cool'));
cb(null, 'yay!');
cb(true);
})(null, function(err, data) {
if (err === true) return;
if (err) throw err;
// Log awaited data.
console.log(data);
});
MIT © Jamen Marz