99 lines
1.9 KiB
JavaScript
99 lines
1.9 KiB
JavaScript
'use strict';
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = DeferredSink;
|
|
|
|
var _task = require('../task');
|
|
|
|
function DeferredSink(sink) {
|
|
this.sink = sink;
|
|
this.events = [];
|
|
this.active = true;
|
|
} /** @license MIT License (c) copyright 2010-2016 original author or authors */
|
|
/** @author Brian Cavalier */
|
|
/** @author John Hann */
|
|
|
|
DeferredSink.prototype.event = function (t, x) {
|
|
if (!this.active) {
|
|
return;
|
|
}
|
|
|
|
if (this.events.length === 0) {
|
|
(0, _task.defer)(new PropagateAllTask(this.sink, t, this.events));
|
|
}
|
|
|
|
this.events.push({ time: t, value: x });
|
|
};
|
|
|
|
DeferredSink.prototype.end = function (t, x) {
|
|
if (!this.active) {
|
|
return;
|
|
}
|
|
|
|
this._end(new EndTask(t, x, this.sink));
|
|
};
|
|
|
|
DeferredSink.prototype.error = function (t, e) {
|
|
this._end(new ErrorTask(t, e, this.sink));
|
|
};
|
|
|
|
DeferredSink.prototype._end = function (task) {
|
|
this.active = false;
|
|
(0, _task.defer)(task);
|
|
};
|
|
|
|
function PropagateAllTask(sink, time, events) {
|
|
this.sink = sink;
|
|
this.events = events;
|
|
this.time = time;
|
|
}
|
|
|
|
PropagateAllTask.prototype.run = function () {
|
|
var this$1 = this;
|
|
|
|
var events = this.events;
|
|
var sink = this.sink;
|
|
var event;
|
|
|
|
for (var i = 0, l = events.length; i < l; ++i) {
|
|
event = events[i];
|
|
this$1.time = event.time;
|
|
sink.event(event.time, event.value);
|
|
}
|
|
|
|
events.length = 0;
|
|
};
|
|
|
|
PropagateAllTask.prototype.error = function (e) {
|
|
this.sink.error(this.time, e);
|
|
};
|
|
|
|
function EndTask(t, x, sink) {
|
|
this.time = t;
|
|
this.value = x;
|
|
this.sink = sink;
|
|
}
|
|
|
|
EndTask.prototype.run = function () {
|
|
this.sink.end(this.time, this.value);
|
|
};
|
|
|
|
EndTask.prototype.error = function (e) {
|
|
this.sink.error(this.time, e);
|
|
};
|
|
|
|
function ErrorTask(t, e, sink) {
|
|
this.time = t;
|
|
this.value = e;
|
|
this.sink = sink;
|
|
}
|
|
|
|
ErrorTask.prototype.run = function () {
|
|
this.sink.error(this.time, this.value);
|
|
};
|
|
|
|
ErrorTask.prototype.error = function (e) {
|
|
throw e;
|
|
}; |