UNPKG

mutual

Version:

Scala-inspired Actors that use Redis as a message transport

63 lines (53 loc) 2.14 kB
// Generated by CoffeeScript 1.12.7 (function() { var RemoteChannel, RemoteQueue, extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty; RemoteChannel = require("./remote-channel"); RemoteQueue = (function(superClass) { extend(RemoteQueue, superClass); function RemoteQueue() { return RemoteQueue.__super__.constructor.apply(this, arguments); } RemoteQueue.prototype.send = function(message) { return this.events.source((function(_this) { return function(events) { var _events; _events = _this.transport.enqueue(_this["package"](message)); return _events.forward(events); }; })(this)); }; RemoteQueue.prototype.listen = function() { return this.events.source((function(_this) { return function(events) { var _dequeue; if (!_this.isListening) { _this.isListening = true; _dequeue = function() { return _this.transport.dequeue(_this.name).on("success", function(message) { var ref, ref1; _this.fire(message); if (((ref = _this.channels[message.event]) != null ? (ref1 = ref.handlers) != null ? ref1.length : void 0 : void 0) > 0) { return setImmediate(_dequeue); } }); }; if (_this.superOn == null) { _this.superOn = _this.on; } _this.on = function(event, handler) { _this.superOn(event, handler); if (event !== "success" && event !== "error" && event !== "ready") { return _dequeue(); } }; return events.emit("success"); } }; })(this)); }; return RemoteQueue; })(RemoteChannel); module.exports = RemoteQueue; }).call(this);