0.1.1 • Published 8 years ago

pull-await v0.1.1

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago

pull-await NPM version Build Status

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']);
  })
);

Installation

$ npm install --save pull-await

Usage

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);
});

License

MIT © Jamen Marz