mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-05-08 08:58:38 +01:00
Fix: clean up batcher timeouts in all cases
This commit is contained in:
+6
-12
@@ -45,6 +45,11 @@ export function createBatcher<ItemType>(
|
||||
const queue = new PQueue({ concurrency: 1, timeout: 1000 * 60 * 2 });
|
||||
|
||||
function _kickBatchOff() {
|
||||
if (timeout) {
|
||||
clearTimeout(timeout);
|
||||
timeout = null;
|
||||
}
|
||||
|
||||
const itemsRef = items;
|
||||
items = [];
|
||||
queue.add(async () => {
|
||||
@@ -58,15 +63,8 @@ export function createBatcher<ItemType>(
|
||||
if (items.length === 1) {
|
||||
// Set timeout once when we just pushed the first item so that the wait
|
||||
// time is bounded by `options.wait` and not extended by further pushes.
|
||||
timeout = setTimeout(() => {
|
||||
timeout = null;
|
||||
_kickBatchOff();
|
||||
}, options.wait);
|
||||
timeout = setTimeout(_kickBatchOff, options.wait);
|
||||
} else if (items.length >= options.maxSize) {
|
||||
if (timeout) {
|
||||
clearTimeout(timeout);
|
||||
timeout = null;
|
||||
}
|
||||
_kickBatchOff();
|
||||
}
|
||||
}
|
||||
@@ -97,10 +95,6 @@ export function createBatcher<ItemType>(
|
||||
window.log.info(
|
||||
`Flushing ${options.name} batcher items.length=${items.length}`
|
||||
);
|
||||
if (timeout) {
|
||||
clearTimeout(timeout);
|
||||
timeout = null;
|
||||
}
|
||||
|
||||
while (anyPending()) {
|
||||
_kickBatchOff();
|
||||
|
||||
Reference in New Issue
Block a user