Git Product home page Git Product logo

promise2stream's Introduction

Transform ES2015 Promise to Stream - specifically, Transform Stream using through2. Works in object mode by default, but you can pass options directly to the through2 package.

code climate standard code style travis build status coverage status dependency status

Install

npm i promise2stream --save

Usage

For more use-cases see the tests

const promise2stream = require('promise2stream')

Transform a Promise val to transform stream.

Params

  • val {Promise}: Some promise.
  • opts {Object}: Options passed directly to through2.
  • returns {Stream}

Example

var promise2stream = require('promise2stream')
var promise = Promise.resolve(123)

var stream = promise2stream(promise)
stream
  .on('data', function (val) {
    console.log(val) // => 123
  })
  .once('error', console.error)
  .once('end', function () {
    console.log('end')
  })

// or access the promise
stream.promise.then(function (val) {
  console.log(val) // => 123
}, console.error)

// rejected promise fires `error` event
var rejectedPromise = Promise.reject(new Error('foo err'))
var stream = promise2stream(rejectedPromise)

stream.once('error', function (err) {
  console.log(err) // => [Error: foo err]
})

Related

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.

tunnckoCore.tk keybase tunnckoCore tunnckoCore npm tunnckoCore twitter tunnckoCore github

promise2stream's People

Contributors

tunnckocore avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

promise2stream's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.