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.
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)
})
.once('error', console.error)
.once('end', function () {
console.log('end')
})
stream.promise.then(function (val) {
console.log(val)
}, console.error)
var rejectedPromise = Promise.reject(new Error('foo err'))
var stream = promise2stream(rejectedPromise)
stream.once('error', function (err) {
console.log(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.