Adding an onCleanup hook to cancel dispatches and watches for Wpt

This commit is contained in:
vdv committed 2022-12-06 14:54:59 +01:00
1 parent 5829f93c91
commit cc121fea27
2 files changed
+22 -6

No files matched your search

+4 -4
View File
@@ -22,9 +22,9 @@ export const init = () => {
payload,
dispatcherQueue: JSON.parse(JSON.stringify(dispatcherQueue)),
});
dispatcherQueue.queue.get(id).callBack(null, payload);
dispatcherQueue.queue.get(id).callBack(null, payload, id);
if (!dispatcherQueue.queue.get(id).live) {
cancel(id);
cancelDispatch(id);
}
};
@@ -33,7 +33,7 @@ export const init = () => {
const dispatch = (
payload: any,
callBack?: (error: any, result: any) => void,
callBack?: (error: any, result: any, id?: number|undefined) => void,
live?: boolean
) => {
console.log({ caller: 'dispatcher-main / dispatch', payload });
@@ -66,7 +66,7 @@ const dispatch = (
});
};
export const cancel = (id: number) => {
export const cancelDispatch = (id: number) => {
dispatcherQueue.queue.delete(id);
};