Bug fix (bad promise magic!)
This commit is contained in:
parent
853b158dcf
commit
51250c1880
|
@ -44,21 +44,19 @@ const dbReady = () => {
|
|||
return watchDbStatus()?.opened;
|
||||
};
|
||||
|
||||
const dispatch = (
|
||||
const dispatch = async (
|
||||
payload: any,
|
||||
callBack?: (error: any, result: any, id?: number | undefined) => void,
|
||||
live?: boolean
|
||||
) => {
|
||||
console.log({ caller: 'dispatcher-main / dispatch', payload });
|
||||
console.log({ caller: 'dispatcher-main / dispatch', payload, callBack });
|
||||
if (worker === undefined) {
|
||||
init();
|
||||
}
|
||||
let returnValue;
|
||||
until(dbReady, 100).then(() => {
|
||||
// Wait until databases have been created by health.ts
|
||||
await until(dbReady, 100); // Wait until databases have been created by health.ts
|
||||
if (callBack === undefined) {
|
||||
/** If a callback function is not provided, return a promise */
|
||||
returnValue = new Promise((resolve, reject) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
dispatch(payload, (error, result) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
|
@ -67,7 +65,7 @@ const dispatch = (
|
|||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
}
|
||||
/** Otherwise, use the callback function */
|
||||
dispatcherQueue.queue.set(dispatcherQueue.index, { callBack, live });
|
||||
const message = {
|
||||
|
@ -80,11 +78,6 @@ const dispatch = (
|
|||
message,
|
||||
dispatcherQueue,
|
||||
});
|
||||
}
|
||||
});
|
||||
if (returnValue) {
|
||||
return returnValue;
|
||||
}
|
||||
};
|
||||
|
||||
export const cancelDispatch = (id: number) => {
|
||||
|
|
Loading…
Reference in New Issue