Comparing version 0.1.0-rc.18 to 0.1.0-rc.19
@@ -74,2 +74,3 @@ import EventEmitter from 'eventemitter3'; | ||
private hasResults; | ||
private cancelled; | ||
constructor(name: string, emitter: EventEmitter, decoder: (payload: Uint8Array) => Promise<T>, gateway: Gateway); | ||
@@ -76,0 +77,0 @@ [Symbol.asyncIterator](): AsyncIterator<T>; |
@@ -167,4 +167,4 @@ "use strict"; | ||
this.events = []; | ||
this.postResults = () => { }; // eslint-disable-line @typescript-eslint/no-empty-function | ||
this.hasResults = new Promise(resolve => (this.postResults = resolve)); | ||
this.cancelled = false; | ||
emitter | ||
@@ -174,3 +174,5 @@ .on(name, ({ data }) => __awaiter(this, void 0, void 0, function* () { | ||
this.postResults(); | ||
this.hasResults = new Promise(resolve => (this.postResults = resolve)); | ||
this.hasResults = new Promise(resolve => { | ||
this.postResults = resolve; | ||
}); | ||
})) | ||
@@ -183,9 +185,11 @@ .on('error', e => { | ||
return __asyncGenerator(this, arguments, function* _a() { | ||
if (this.events.length > 0) { | ||
while (!this.cancelled) { | ||
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 = []; | ||
}); | ||
@@ -198,2 +202,5 @@ } | ||
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); | ||
@@ -200,0 +207,0 @@ }); |
{ | ||
"name": "oasis-std", | ||
"version": "0.1.0-rc.18", | ||
"version": "0.1.0-rc.19", | ||
"description": "Oasis platform standard library", | ||
@@ -30,3 +30,3 @@ "license": "Apache-2.0", | ||
}, | ||
"gitHead": "53bfbac97735e25d36bc3e7a2883dba4ebcdffab" | ||
"gitHead": "c8f11b7a696b6661e99a3cd52a641e78aa85206b" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
282954
1579