Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

pull-thenable

1.0.0 • Public • Published

pull-thenable

Converts a pull-stream to an object with .then(), usable also with async-await

npm install --save pull-thenable

Usage

As a chain of then's:

const pull = require('pull-stream')
const thenable = require('pull-thenable')
 
const stream = pull.values(['a','b']);
const source = thenable(stream);
 
source.then(x => {
  console.log(x); // 'a'
  return source;
}).then(x => {
  console.log(x); // 'b'
  return source;
}).then(x => {
  // not called
}, err => {
  console.log(err); // true
})

With async-await:

const pull = require('pull-stream')
const thenable = require('pull-thenable')
 
const stream = pull.values(['a','b']);
const source = thenable(stream);
 
async function main() {
  while (true) {
    try {
      const x = await thenable(readable);
      console.log(x); // 'a'
                      // 'b'
    } catch (errOrEnd) {
      console.log(errOrEnd); // true
      return;
    }
  }
}
 
main();

License

MIT

install

npm i pull-thenable

Downloadsweekly downloads

3

version

1.0.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability