diff --git a/ts/util/batcher.ts b/ts/util/batcher.ts index 55c711d9a4..f4e620dd87 100644 --- a/ts/util/batcher.ts +++ b/ts/util/batcher.ts @@ -6,7 +6,7 @@ window.batchers = []; // @ts-ignore window.waitForAllBatchers = async () => { // @ts-ignore - await Promise.all(window.batchers.map(item => item.onIdle())); + await Promise.all(window.batchers.map(item => item.flushAndWait())); }; type BatcherOptionsType = { @@ -19,6 +19,7 @@ type BatcherType = { add: (item: ItemType) => void; anyPending: () => boolean; onIdle: () => Promise; + flushAndWait: () => Promise; unregister: () => void; }; @@ -83,10 +84,23 @@ export function createBatcher( window.batchers = window.batchers.filter((item: any) => item !== batcher); } + async function flushAndWait() { + if (timeout) { + clearTimeout(timeout); + timeout = null; + } + if (items.length) { + _kickBatchOff(); + } + + return onIdle(); + } + batcher = { add, anyPending, onIdle, + flushAndWait, unregister, };