A readable stream to which you can in random order push chunks or sub-streams with an index, and they will be emitted by index ascending.
var Orderable = require('orderable');
var o = Orderable();
setTimeout(function(){
o.set(0, 'foo\n');
}, Math.random() * 1000);
setTimeout(function(){
o.set(1, createStringStream(['b', 'a', 'r', '\n']));
}, Math.random() * 1000);
setTimeout(function(){
o.set(2, 'baz\n');
o.set(3, null);
}, Math.random() * 1000);
o.pipe(process.stdout);
Always outputs:
$ node example.js
foo
bar
baz
$
$ npm install orderable
Create an orderable stream.
Push chunk
onto the internal buffer at index
. Pass chunk=null
to mark the end of a stream. You can pass readable streams as well.
You can also do this at the beginning, like:
o.set(3, null);
o.set(0, 'foo');
o.set(1, 'bar');
o.set(2, 'baz');
MIT