streams-to-promise
v1.0.2
Published
Promises conclusion of multiple streams (readable or writable)
Downloads
2
Maintainers
Readme
streams-to-promise
Promises conclusion of multiple streams (readable or writable)
Based on Ben Drucker's stream-to-promise
, it expands the functionality for multiple streams.
Installation
npm install streams-to-promise
var all = require('streams-to-promise');
var { all, race } = require('streams-to-promise');
Examples
Promising conclusion of all streams
var promiseAllStreams = require('streams-to-promise');
var stream1 = ...;
var stream2 = ...;
...
var streamN = ...;
promiseAllStreams(stream1, stream2, ..., streamN).then(function (results) {
// results[0] -> streamed data from stream1
// results[1] -> streamed data from stream2
// ...
// results[N-1] -> streamed data from streamN
});
Racing conclusion of streams
var raceStreams = require('streams-to-promise').race;
var stream1 = ...;
var stream2 = ...;
...
var streamN = ...;
raceStreams(stream1, stream2, ..., streamN).then(function (result) {
// result -> streamed data from stream that concluded first
});
Usage with Gulp
...
var { all, race } = require('streams-to-promise');
gulp.task('mytask', () => {
...
// Performs stream operations in parallel and promises its conclusion
//
return all(
gulp.src(...)
.pipe(...)
.pipe(...),
gulp.src(...)
.pipe(...)
.pipe(...),
...
);
});
API
all([s1[, s2[, ...[, sN]]]])
var all = require('streams-to-promise');
var all = require('streams-to-promise').all;
s1
,s2
, ...,sN
: Readable, Writable, ReadStream, WriteStream streamsreturns an
any-promise
promise (defaults to an ES6 Promise) that, once all passed streams have concluded, will resolve an array with all the streamed data of each passed stream.
race([s1[, s2[, ...[, sN]]]])
var race = require('streams-to-promise').race;
s1
,s2
, ...,sN
: Readable, Writable, ReadStream, WriteStream streamsreturns an
any-promise
promise (defaults to an ES6 Promise) that will resolve the streamed data of the passed stream that concludes first.
License
MIT