Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[fix] allow for correct error propagation from reactors
  • Loading branch information
jcrugzz committed Jul 18, 2013
1 parent b5d8204 commit 60a5366
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/godot/net/server.js
Expand Up @@ -70,6 +70,7 @@ utile.inherits(Server, events.EventEmitter);
//
Server.prototype.add = function (reactor) {
this.emit('add', reactor);
reactor.on('error', this.emit.bind(this, 'error'));
this.reactors[reactor.id] = reactor;
};

Expand All @@ -82,6 +83,7 @@ Server.prototype.add = function (reactor) {
//
Server.prototype.remove = function (reactor) {
this.emit('remove', reactor);
this.reactors[reactor.id].removeAllListeners();
delete this.reactors[reactor.id];

//
Expand Down
15 changes: 11 additions & 4 deletions lib/godot/reactor/reactor.js
Expand Up @@ -5,7 +5,8 @@
*
*/

var utile = require('utile'),
var EventEmitter = require('events').EventEmitter,
util = require('util'),
uuid = require('node-uuid'),
ReadWriteStream = require('../common/read-write-stream');

Expand All @@ -16,6 +17,7 @@ var utile = require('utile'),
// pipe chains of streams for reacting to events.
//
var Reactor = module.exports = function Reactor(options) {
EventEmitter.call(this);
options = options || {};

if (typeof options === 'string') {
Expand All @@ -27,6 +29,11 @@ var Reactor = module.exports = function Reactor(options) {
this.name = options.name;
};

//
// Inherit from event emitter for error propagation
//
util.inherits(Reactor, EventEmitter);

//
// ### function createStream ()
// Instantiates a new and unique pipe-chain for the reactors
Expand Down Expand Up @@ -64,8 +71,8 @@ Reactor.prototype.createStream = function (source) {
}

return this.reactors.reduce(function (last, nextOptions) {
return last.pipe(
wrapStream(nextOptions.Factory, nextOptions.args || [])
);
var stream = wrapStream(nextOptions.Factory, nextOptions.args || []);
stream.on('error', self.emit.bind(self, 'error'));
return last.pipe(stream);
}, source);
};

0 comments on commit 60a5366

Please sign in to comment.