fix worker queue bug
This commit is contained in:
parent
99f5eaa095
commit
af10553b32
@ -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++;
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user