@iexec/iexec-oracle-factory-wrapper
Version:
A wrapper for creating API based oracles for ethereum on the top of iExec
70 lines • 1.84 kB
JavaScript
export class SafeObserver {
destination;
unsub;
isUnsubscribed = false;
constructor(destination) {
this.destination = destination;
}
next(value) {
if (!this.isUnsubscribed && this.destination.next) {
try {
this.destination.next(value);
}
catch (err) {
this.unsubscribe();
throw err;
}
}
}
error(err) {
if (!this.isUnsubscribed && this.destination.error) {
try {
this.destination.error(err);
}
catch (e2) {
this.unsubscribe();
throw e2;
}
this.unsubscribe();
}
}
complete() {
if (!this.isUnsubscribed && this.destination.complete) {
try {
this.destination.complete();
}
catch (err) {
this.unsubscribe();
throw err;
}
this.unsubscribe();
}
}
unsubscribe() {
this.isUnsubscribed = true;
if (this.unsub) {
this.unsub();
}
}
}
export class Observable {
_subscribe;
constructor(_subscribe) {
this._subscribe = _subscribe;
}
subscribe(observerOrNext, error, complete) {
const safeObserver = new SafeObserver(observerOrNext);
if (typeof observerOrNext === 'function') {
safeObserver.destination = {
next: observerOrNext,
error: error,
complete: complete,
};
}
else if (typeof observerOrNext === 'object') {
safeObserver.destination = observerOrNext;
}
return this._subscribe(safeObserver);
}
}
//# sourceMappingURL=reactive.js.map