Skip to content

Latest commit

 

History

History
92 lines (77 loc) · 2.38 KB

README.md

File metadata and controls

92 lines (77 loc) · 2.38 KB

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 Readable stream that will consume the provided streams in strict order. The produced Readable stream respects backpressure on itself and any provided streams.

License

MIT