Flush all watchers on empty queue

This commit is contained in:
Fedor Indutny 2021-03-25 17:00:03 -07:00 committed by GitHub
parent 67892d838c
commit 746e99b8c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 317 additions and 89 deletions

View file

@ -204,16 +204,23 @@ class MessageReceiverInner extends EventTarget {
this.appQueue = new PQueue({ concurrency: 1, timeout: 1000 * 60 * 2 });
this.cacheAddBatcher = createBatcher<CacheAddItemType>({
name: 'MessageReceiver.cacheAddBatcher',
wait: 200,
maxSize: 30,
processBatch: this.cacheAndQueueBatch.bind(this),
processBatch: (items: Array<CacheAddItemType>) => {
// Not returning the promise here because we don't want to stall
// the batch.
this.cacheAndQueueBatch(items);
},
});
this.cacheUpdateBatcher = createBatcher<CacheUpdateItemType>({
name: 'MessageReceiver.cacheUpdateBatcher',
wait: 500,
maxSize: 30,
processBatch: this.cacheUpdateBatch.bind(this),
});
this.cacheRemoveBatcher = createBatcher<string>({
name: 'MessageReceiver.cacheRemoveBatcher',
wait: 500,
maxSize: 30,
processBatch: this.cacheRemoveBatch.bind(this),
@ -507,7 +514,13 @@ class MessageReceiverInner extends EventTarget {
}
onEmpty() {
const emitEmpty = () => {
const emitEmpty = async () => {
await Promise.all([
this.cacheAddBatcher.flushAndWait(),
this.cacheUpdateBatcher.flushAndWait(),
this.cacheRemoveBatcher.flushAndWait(),
]);
window.log.info("MessageReceiver: emitting 'empty' event");
const ev = new Event('empty');
this.dispatchEvent(ev);