Fix a weird race condition where the worker wouldn't be ready when it needed to be
This commit is contained in:
parent
872f67d908
commit
61607dc75d
|
@ -52,12 +52,14 @@ const handleRollWorker = async (rq: QueuedRoll) => {
|
||||||
}
|
}
|
||||||
}, config.limits.workerTimeout);
|
}, config.limits.workerTimeout);
|
||||||
|
|
||||||
|
rollWorker.addEventListener('message', async (workerMessage) => {
|
||||||
|
if (workerMessage.data === 'ready') {
|
||||||
rollWorker.postMessage({
|
rollWorker.postMessage({
|
||||||
rollCmd: rq.rollCmd,
|
rollCmd: rq.rollCmd,
|
||||||
modifiers: rq.modifiers,
|
modifiers: rq.modifiers,
|
||||||
});
|
});
|
||||||
|
return;
|
||||||
rollWorker.addEventListener('message', async (workerMessage) => {
|
}
|
||||||
let apiErroredOut = false;
|
let apiErroredOut = false;
|
||||||
try {
|
try {
|
||||||
currentWorkers--;
|
currentWorkers--;
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
import { parseRoll } from './parser.ts';
|
import { parseRoll } from './parser.ts';
|
||||||
|
|
||||||
|
// Alert rollQueue that this worker is ready
|
||||||
|
self.postMessage('ready');
|
||||||
|
|
||||||
|
// Handle the roll
|
||||||
self.onmessage = async (e: any) => {
|
self.onmessage = async (e: any) => {
|
||||||
const payload = e.data;
|
const payload = e.data;
|
||||||
const returnmsg = parseRoll(payload.rollCmd, payload.modifiers) || {
|
const returnmsg = parseRoll(payload.rollCmd, payload.modifiers) || {
|
||||||
|
|
Loading…
Reference in New Issue