UNPKG

mutual

Version:

Scala-inspired Actors that use Redis as a message transport

79 lines (66 loc) 1.79 kB
// Generated by CoffeeScript 1.12.7 (function() { var Channel; Channel = (function() { function Channel() { this.handlers = []; } Channel.prototype.send = function(message) { return setImmediate((function(_this) { return function() { return _this.fire(message); }; })(this)); }; Channel.prototype.fire = function(message) { var handler, i, len, ref, results; this["package"](message); ref = this.handlers; results = []; for (i = 0, len = ref.length; i < len; i++) { handler = ref[i]; results.push(handler(message)); } return results; }; Channel.prototype.receive = function(handler) { return this.handlers.push(handler); }; Channel.prototype.remove = function(handler) { var _handler; return this.handlers = (function() { var i, len, ref, results; ref = this.handlers; results = []; for (i = 0, len = ref.length; i < len; i++) { _handler = ref[i]; if (_handler !== handler) { results.push(_handler); } } return results; }).call(this); }; Channel.prototype.forward = function(channel) { return this.receive((function(_this) { return function(message) { return channel.fire(message); }; })(this)); }; Channel.prototype.source = function(block) { var channel; channel = new this.constructor; channel.forward(this); if (block != null) { block(channel); } return channel; }; Channel.prototype["package"] = function(message) { return message; }; return Channel; })(); module.exports = Channel; }).call(this);