push
github
1694 of 1700 branches covered (99.65%)
1 of 1 new or added line in 1 file covered. (100.0%)
2131 of 2131 relevant lines covered (100.0%)
135.36 hits per line
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); |
501✔ |
7 |
} |
|
8 |
|
|
9 |
export function clear(fn) { |
|
10 |
queue.delete(fn);
|
198✔ |
11 |
} |
|
12 |
|
|
13 |
function execute() { |
|
14 |
for (const fn of queue) {
|
159✔ |
15 |
try {
|
498✔ |
16 |
fn(); |
498✔ |
17 |
} catch (e) {
|
|
18 |
console.error(e); |
5✔ |
19 |
} |
|
20 |
} |
|
21 |
|
|
22 |
queue.clear(); |
159✔ |
23 |
} |