signal-desktop/ts/util/StartupQueue.ts
2021-03-19 16:57:35 -04:00

30 lines
570 B
TypeScript

// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
export class StartupQueue {
set: Set<string>;
items: Array<() => void>;
constructor() {
this.set = new Set();
this.items = [];
}
add(id: string, f: () => void): void {
if (this.set.has(id)) {
return;
}
this.items.push(f);
this.set.add(id);
}
flush(): void {
const { items } = this;
window.log.info('StartupQueue: Processing', items.length, 'actions');
items.forEach(f => f());
this.items = [];
this.set.clear();
}
}