0.2.0 • Published 9 years ago

ostream v0.2.0

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

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

0.2.0

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago

0.0.1

9 years ago