This commit is contained in:
vdv committed 2023-02-11 17:52:11 +01:00
1 parent 79fed3cc28
commit 853b158dcf
3 files changed
+91 -90

No files matched your search

+19 -14
View File
@@ -53,11 +53,12 @@ const dispatch = (
if (worker === undefined) {
init();
}
until(dbReady, 1000).then(() => {
let returnValue;
until(dbReady, 100).then(() => {
// Wait until databases have been created by health.ts
if (callBack === undefined) {
/** If a callback function is not provided, return a promise */
return new Promise((resolve, reject) => {
returnValue = new Promise((resolve, reject) => {
dispatch(payload, (error, result) => {
if (error) {
reject(error);
@@ -66,20 +67,24 @@ const dispatch = (
}
});
});
} else {
/** Otherwise, use the callback function */
dispatcherQueue.queue.set(dispatcherQueue.index, { callBack, live });
const message = {
id: dispatcherQueue.index++,
payload: payload,
};
worker.postMessage(message);
console.log({
caller: 'dispatcher-main / message sent',
message,
dispatcherQueue,
});
}
/** Otherwise, use the callback function */
dispatcherQueue.queue.set(dispatcherQueue.index, { callBack, live });
const message = {
id: dispatcherQueue.index++,
payload: payload,
};
worker.postMessage(message);
console.log({
caller: 'dispatcher-main / message sent',
message,
dispatcherQueue,
});
});
if (returnValue) {
return returnValue;
}
};
export const cancelDispatch = (id: number) => {