All Projects → gulpjs → ordered-read-streams

gulpjs / ordered-read-streams

Licence: MIT license
Combines array of streams into one Readable stream in strict order.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to ordered-read-streams

readable-web-to-node-stream
Converts a Web-API readable-stream into a Node readable-stream.
Stars: ✭ 33 (+22.22%)
Mutual labels:  readable-stream

ordered-read-streams

NPM version Downloads Build Status Coveralls Status

Combines array of streams into one Readable stream in strict order.

Usage

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].