1 |
import { deferred } from "./utils.js"; |
|
2 |
|
|
3 |
const queue = new Set();
|
2✔ |
4 |
export function add(fn) { |
|
5 |
if (!queue.size) deferred.then(execute);
|
|
6 |
queue.add(fn); |
313✔ |
7 |
} |
|
8 |
|
|
9 |
export function clear(fn) { |
|
10 |
queue.delete(fn);
|
215✔ |
11 |
} |
|
12 |
|
|
13 |
function execute() { |
|
14 |
for (const fn of queue) {
|
158✔ |
15 |
try {
|
313✔ |
16 |
fn(); |
313✔ |
17 |
} catch (e) {
|
|
18 |
console.error(e); |
7✔ |
19 |
} |
|
20 |
} |
|
21 |
|
|
22 |
queue.clear(); |
158✔ |
23 |
} |