Sha256: 8d3259fa4cdc5aaaffcd61c5fd68374dd7631649db7949f3374ba3d0c41db65e
Contents?: true
Size: 1.87 KB
Versions: 14
Compression:
Stored size: 1.87 KB
Contents
function MockPromise(scheduler, messages) { var self = this; this.scheduler = scheduler; this.messages = messages; this.subscriptions = []; this.observers = []; for (var i = 0, len = this.messages.length; i < len; i++) { var message = this.messages[i], notification = message.value; (function (innerNotification) { scheduler.scheduleAbsoluteWithState(null, message.time, function () { var obs = self.observers.slice(0); for (var j = 0, jLen = obs.length; j < jLen; j++) { innerNotification.accept(obs[j]); } return disposableEmpty; }); })(notification); } } MockPromise.prototype.then = function (onResolved, onRejected) { var self = this; this.subscriptions.push(new Subscription(this.scheduler.clock)); var index = this.subscriptions.length - 1; var newPromise; var observer = Rx.Observer.create( function (x) { var retValue = onResolved(x); if (retValue && typeof retValue.then === 'function') { newPromise = retValue; } else { var ticks = self.scheduler.clock; newPromise = new MockPromise(self.scheduler, [Rx.ReactiveTest.onNext(ticks, undefined), Rx.ReactiveTest.onCompleted(ticks)]); } var idx = self.observers.indexOf(observer); self.observers.splice(idx, 1); self.subscriptions[index] = new Subscription(self.subscriptions[index].subscribe, self.scheduler.clock); }, function (err) { onRejected(err); var idx = self.observers.indexOf(observer); self.observers.splice(idx, 1); self.subscriptions[index] = new Subscription(self.subscriptions[index].subscribe, self.scheduler.clock); } ); this.observers.push(observer); return newPromise || new MockPromise(this.scheduler, this.messages); };
Version data entries
14 entries across 7 versions & 1 rubygems