aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2016-09-28 17:45:13 +0200
committerFlorian Dold <florian.dold@gmail.com>2016-09-28 17:45:13 +0200
commitaf10553b32e549143f01744b2e9602eb0a3d0621 (patch)
treeaea4943790daa795ab5c9d50e0789b2fbdd0ddb8 /lib
parent99f5eaa095f8aea4027cae611f6681a2d517337e (diff)
downloadwallet-core-af10553b32e549143f01744b2e9602eb0a3d0621.tar.xz
fix worker queue bug
Diffstat (limited to 'lib')
-rw-r--r--lib/wallet/cryptoApi.ts12
1 files changed, 10 insertions, 2 deletions
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<T>((resolve, reject) => {
let msg: any = {
operation, args,
id: this.registerRpcId(resolve, reject, i),
};
ws.w.postMessage(msg);
- ws.busy = true;
- this.numBusy++;
});
}