Socket
Book a DemoInstallSign in
Socket

pull-thenable

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pull-thenable

Convert a pull-stream into a thenable

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
3.1K
292.9%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

pull-stream

FAQs

Package last updated on 03 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts