Comparing version
@@ -75,9 +75,5 @@ import EventEmitter from 'eventemitter3'; | ||
private hasResults; | ||
private cancelled; | ||
constructor(name: string, emitter: EventEmitter, decoder: (payload: Uint8Array) => Promise<T>, gateway: Gateway); | ||
[Symbol.asyncIterator](): AsyncIterator<T>; | ||
/** | ||
* Cancels this Subscription. No further events will be yielded. | ||
*/ | ||
cancel(): Promise<void>; | ||
first(): Promise<T>; | ||
} |
@@ -189,3 +189,2 @@ "use strict"; | ||
this.hasResults = new Promise((resolve) => (this.postResults = resolve)); | ||
this.cancelled = false; | ||
emitter | ||
@@ -205,22 +204,35 @@ .on(name, ({ data }) => __awaiter(this, void 0, void 0, function* () { | ||
return __asyncGenerator(this, arguments, function* _a() { | ||
while (!this.cancelled) { | ||
if (this.events.length > 0) { | ||
try { | ||
while (true) { | ||
if (this.events.length > 0) { | ||
yield __await(yield* __asyncDelegator(__asyncValues(this.events))); | ||
this.events = []; | ||
} | ||
yield __await(this.hasResults); | ||
yield __await(yield* __asyncDelegator(__asyncValues(this.events))); | ||
this.events = []; | ||
} | ||
yield __await(this.hasResults); | ||
yield __await(yield* __asyncDelegator(__asyncValues(this.events))); | ||
this.events = []; | ||
} | ||
finally { | ||
yield __await(this.gateway['unsubscribe'](this.name)); | ||
} | ||
}); | ||
} | ||
/** | ||
* Cancels this Subscription. No further events will be yielded. | ||
*/ | ||
cancel() { | ||
first() { | ||
var e_1, _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.cancelled = true; | ||
this.events = []; // satisfy doc comment | ||
this.postResults(); // cause a pending `for await` to resolve | ||
yield this.gateway.unsubscribe(this.name); | ||
try { | ||
for (var _b = __asyncValues(this), _c; _c = yield _b.next(), !_c.done;) { | ||
const event = _c.value; | ||
return event; | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
throw new Error('Subscription closed before the first event'); | ||
}); | ||
@@ -227,0 +239,0 @@ } |
{ | ||
"name": "oasis-std", | ||
"version": "0.1.0-rc.24", | ||
"version": "0.1.0-rc.25", | ||
"description": "Oasis platform standard library", | ||
@@ -27,3 +27,3 @@ "license": "Apache-2.0", | ||
}, | ||
"gitHead": "d25495a596c15340f9527d7fd143e516bb381e5b" | ||
"gitHead": "7e4e39d5ee7ad12ef6faa3b906d474290ee1b81a" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
273452
0.11%1749
0.46%