1 | import { Trace } from '../trace';
|
2 | import { dispatchToMainThread } from './mainthread-helper';
|
3 | let scheduled = false;
|
4 | let macroTaskQueue = [];
|
5 | function drainMacrotaskQueue() {
|
6 | const currentQueue = macroTaskQueue;
|
7 | macroTaskQueue = [];
|
8 | scheduled = false;
|
9 | currentQueue.forEach((task) => {
|
10 | try {
|
11 | task();
|
12 | }
|
13 | catch (err) {
|
14 | const msg = err ? err.stack || err : err;
|
15 | Trace.write(`Error in macroTask: ${msg}`, Trace.categories.Error, Trace.messageType.error);
|
16 | }
|
17 | });
|
18 | }
|
19 | export function queueMacrotask(task) {
|
20 | macroTaskQueue.push(task);
|
21 | if (!scheduled) {
|
22 | scheduled = true;
|
23 | dispatchToMainThread(drainMacrotaskQueue);
|
24 | }
|
25 | }
|
26 |
|
\ | No newline at end of file |