UNPKG

769 BJavaScriptView Raw
1import { Trace } from '../trace';
2import { dispatchToMainThread } from './mainthread-helper';
3let scheduled = false;
4let macroTaskQueue = [];
5function 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}
19export function queueMacrotask(task) {
20 macroTaskQueue.push(task);
21 if (!scheduled) {
22 scheduled = true;
23 dispatchToMainThread(drainMacrotaskQueue);
24 }
25}
26//# sourceMappingURL=macrotask-scheduler.js.map
\No newline at end of file