UNPKG

@emartech/faye-redis-sharded

Version:

Redis backend engine for Faye with support for sharding

45 lines (37 loc) 1.1 kB
Faye.Deferrable = { then: function(callback, errback) { var self = this; if (!this._promise) this._promise = new Faye.Promise(function(fulfill, reject) { self._fulfill = fulfill; self._reject = reject; }); if (arguments.length === 0) return this._promise; else return this._promise.then(callback, errback); }, callback: function(callback, context) { return this.then(function(value) { callback.call(context, value) }); }, errback: function(callback, context) { return this.then(null, function(reason) { callback.call(context, reason) }); }, timeout: function(seconds, message) { this.then(); var self = this; this._timer = Faye.ENV.setTimeout(function() { self._reject(message); }, seconds * 1000); }, setDeferredStatus: function(status, value) { if (this._timer) Faye.ENV.clearTimeout(this._timer); this.then(); if (status === 'succeeded') this._fulfill(value); else if (status === 'failed') this._reject(value); else delete this._promise; } };