https://github.com/gulpjs/ordered-read-streams
Combines array of streams into one Readable stream in strict order.
https://github.com/gulpjs/ordered-read-streams
javascript readable-stream stream streamx
Last synced: about 2 months ago
JSON representation
Combines array of streams into one Readable stream in strict order.
- Host: GitHub
- URL: https://github.com/gulpjs/ordered-read-streams
- Owner: gulpjs
- License: mit
- Created: 2014-01-14T16:07:47.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2023-04-15T22:14:56.000Z (about 2 years ago)
- Last Synced: 2024-10-29T15:14:37.160Z (7 months ago)
- Topics: javascript, readable-stream, stream, streamx
- Language: JavaScript
- Homepage:
- Size: 41 KB
- Stars: 28
- Watchers: 6
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# ordered-read-streams
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][ci-image]][ci-url] [![Coveralls Status][coveralls-image]][coveralls-url]
Combines array of streams into one Readable stream in strict order.
## Usage
```js
var { Readable } = require('streamx');
var ordered = require('ordered-read-streams');var s1 = new Readable({
read: function (cb) {
var self = this;
if (self.called) {
self.push(null);
return cb(null);
}
setTimeout(function () {
self.called = true;
self.push('stream 1');
cb(null);
}, 200);
},
});
var s2 = new Readable({
read: function (cb) {
var self = this;
if (self.called) {
self.push(null);
return cb(null);
}
setTimeout(function () {
self.called = true;
self.push('stream 2');
cb(null);
}, 30);
},
});
var s3 = new Readable({
read: function (cb) {
var self = this;
if (self.called) {
self.push(null);
return cb(null);
}
setTimeout(function () {
self.called = true;
self.push('stream 3');
cb(null);
}, 100);
},
});var readable = ordered([s1, s2, s3]);
readable.on('data', function (data) {
console.log(data);
// Logs:
// stream 1
// stream 2
// stream 3
});
```## API
### `ordered(streams, [options])`
Takes an array of `Readable` streams and produces a single `OrderedReadable` stream that will consume the provided streams in strict order. The produced `Readable` stream respects backpressure on itself and any provided streams.
#### `orderedReadable.addSource(stream)`
The returned `Readable` stream has an `addSource` instance function that takes appends a `Readable` stream to the list of source streams that the `OrderedReadable` is reading from.
## License
MIT
[downloads-image]: https://img.shields.io/npm/dm/ordered-read-streams.svg?style=flat-square
[npm-url]: https://www.npmjs.com/package/ordered-read-streams
[npm-image]: https://img.shields.io/npm/v/ordered-read-streams.svg?style=flat-square[ci-url]: https://github.com/gulpjs/ordered-read-streams/actions?query=workflow:dev
[ci-image]: https://img.shields.io/github/actions/workflow/status/gulpjs/ordered-read-streams/dev.yml?branch=master&style=flat-square[coveralls-url]: https://coveralls.io/r/gulpjs/ordered-read-streams
[coveralls-image]: https://img.shields.io/coveralls/gulpjs/ordered-read-streams/master.svg?style=flat-square