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];
|
let {resolve, workerIndex} = this.rpcRegistry[id];
|
||||||
delete this.rpcRegistry[id];
|
delete this.rpcRegistry[id];
|
||||||
let ws = this.workers[workerIndex];
|
let ws = this.workers[workerIndex];
|
||||||
|
if (!ws.busy) {
|
||||||
|
throw Error("assertion failed");
|
||||||
|
}
|
||||||
ws.busy = false;
|
ws.busy = false;
|
||||||
this.numBusy--;
|
this.numBusy--;
|
||||||
resolve(msg.data.result);
|
resolve(msg.data.result);
|
||||||
@ -105,6 +108,7 @@ export class CryptoApi {
|
|||||||
ws.w.postMessage(msg);
|
ws.w.postMessage(msg);
|
||||||
ws.busy = true;
|
ws.busy = true;
|
||||||
this.numBusy++;
|
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++) {
|
for (let i = 0; i < this.workers.length; i++) {
|
||||||
let ws = this.workers[i];
|
let ws = this.workers[i];
|
||||||
if (ws.busy) {
|
if (ws.busy) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ws.busy = true;
|
||||||
|
this.numBusy++;
|
||||||
|
|
||||||
return new Promise<T>((resolve, reject) => {
|
return new Promise<T>((resolve, reject) => {
|
||||||
let msg: any = {
|
let msg: any = {
|
||||||
operation, args,
|
operation, args,
|
||||||
id: this.registerRpcId(resolve, reject, i),
|
id: this.registerRpcId(resolve, reject, i),
|
||||||
};
|
};
|
||||||
ws.w.postMessage(msg);
|
ws.w.postMessage(msg);
|
||||||
ws.busy = true;
|
|
||||||
this.numBusy++;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user