File size: 1,700 Bytes
0936134 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | /**
* Created - 6/1/2017
* @author Paul Daniels
*/
'use strict';
export class Sink {
constructor(next, error, complete, context) {
this._next || (this._next = next);
this._error || (this._error = error);
this._complete || (this._complete = complete);
this.context = context || this;
this.isStopped = false;
this.sub = null;
}
run(source) {
return this.sub || (this.sub = source.subscribe(this));
}
next(v) {
if (!this.isStopped) {
this._next.call(this.context, v);
}
}
complete() {
if (!this.isStopped) {
this._complete.call(this.context);
this.unsubscribe();
}
}
error(e) {
if (!this.isStopped) {
this._error.call(this.context, e);
this.unsubscribe();
}
}
unsubscribe() {
if (!this.isStopped) {
this._unsubscribe();
this.sub && this.sub.unsubscribe();
this.isStopped = true;
}
}
_unsubscribe() {}
}
'use strict';
export class ProtectedSink {
constructor(underlying) {
this.underlying = underlying;
this.isStopped = false;
this.sub = null;
}
run(source) {
return this.sub || (this.sub = source.subscribe(this));
}
next(v) {
if (!this.isStopped) {
this.underlying.next(v, this);
}
}
complete() {
if (!this.isStopped) {
this.underlying.complete(this);
this.unsubscribe();
}
}
error(e) {
if (!this.isStopped) {
this.underlying.error(e, this);
this.unsubscribe();
}
}
unsubscribe() {
if (!this.isStopped) {
this.underlying.unsubscribe && this.underlying.unsubscribe();
this.sub && this.sub.unsubscribe();
this.isStopped = true;
}
}
} |