From af10553b32e549143f01744b2e9602eb0a3d0621 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 28 Sep 2016 17:45:13 +0200 Subject: fix worker queue bug --- lib/wallet/cryptoApi.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib/wallet/cryptoApi.ts') diff --git a/lib/wallet/cryptoApi.ts b/lib/wallet/cryptoApi.ts index 62f51f450..4b4a2e5dd 100644 --- a/lib/wallet/cryptoApi.ts +++ b/lib/wallet/cryptoApi.ts @@ -88,6 +88,9 @@ export class CryptoApi { let {resolve, workerIndex} = this.rpcRegistry[id]; delete this.rpcRegistry[id]; let ws = this.workers[workerIndex]; + if (!ws.busy) { + throw Error("assertion failed"); + } ws.busy = false; this.numBusy--; resolve(msg.data.result); @@ -105,6 +108,7 @@ export class CryptoApi { ws.w.postMessage(msg); ws.busy = true; this.numBusy++; + return; } } }; @@ -146,20 +150,24 @@ export class CryptoApi { }); } + console.log(`${this.numBusy} of ${this.workers.length} workers are busy`); + console.log(this.workers); + for (let i = 0; i < this.workers.length; i++) { let ws = this.workers[i]; if (ws.busy) { continue; } + ws.busy = true; + this.numBusy++; + return new Promise((resolve, reject) => { let msg: any = { operation, args, id: this.registerRpcId(resolve, reject, i), }; ws.w.postMessage(msg); - ws.busy = true; - this.numBusy++; }); } -- cgit v1.2.3