ostream
v0.2.0
Published
object stream
Downloads
1
Readme
ostream
Experimenting with EventEmitter to naively implement an 'object' producer-consumer thingy
Install
npm install ostream --save
Usage
var ostream = require('ostream');
var Q = require('q');
// define a producer
var producer = new ostream.Producer();
producer.count = 10;
producer.produce = function () {
var def = Q.defer();
if (this.count > 0) def.resolve(this.count--);
else def.reject(this.count);
return def.promise;
}
// define a consumer
var consumer = new ostream.Consumer();
consumer.sum = 0;
consumer.consume = function (data) {
this.sum += data;
}
// define your data channel/stream
var channel = new ostream.Channel(consumer, producer);
channel.on('end', function () {
console.log(consumer.sum); // should output 55
});
// start producer-consumer data exchange
channel.launch();
TODO
add support for timeout
Changelog
version : 0.2.0
added support for promises, now ostream.Producer.produce should return a q.Promise