|
|
@ -10,33 +10,59 @@ let is_micro_task_queued = false;
|
|
|
|
let is_idle_task_queued = false;
|
|
|
|
let is_idle_task_queued = false;
|
|
|
|
|
|
|
|
|
|
|
|
/** @type {Array<() => void>} */
|
|
|
|
/** @type {Array<() => void>} */
|
|
|
|
let current_queued_micro_tasks = [];
|
|
|
|
let queued_before_microtasks = [];
|
|
|
|
/** @type {Array<() => void>} */
|
|
|
|
/** @type {Array<() => void>} */
|
|
|
|
let current_queued_idle_tasks = [];
|
|
|
|
let queued_after_microtasks = [];
|
|
|
|
|
|
|
|
/** @type {Array<() => void>} */
|
|
|
|
|
|
|
|
let queued_idle_tasks = [];
|
|
|
|
|
|
|
|
|
|
|
|
function process_micro_tasks() {
|
|
|
|
export function flush_before_micro_tasks() {
|
|
|
|
is_micro_task_queued = false;
|
|
|
|
const tasks = queued_before_microtasks.slice();
|
|
|
|
const tasks = current_queued_micro_tasks.slice();
|
|
|
|
queued_before_microtasks = [];
|
|
|
|
current_queued_micro_tasks = [];
|
|
|
|
run_all(tasks);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function flush_after_micro_tasks() {
|
|
|
|
|
|
|
|
const tasks = queued_after_microtasks.slice();
|
|
|
|
|
|
|
|
queued_after_microtasks = [];
|
|
|
|
run_all(tasks);
|
|
|
|
run_all(tasks);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function process_micro_tasks() {
|
|
|
|
|
|
|
|
if (is_micro_task_queued) {
|
|
|
|
|
|
|
|
is_micro_task_queued = false;
|
|
|
|
|
|
|
|
flush_before_micro_tasks();
|
|
|
|
|
|
|
|
flush_after_micro_tasks();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function process_idle_tasks() {
|
|
|
|
function process_idle_tasks() {
|
|
|
|
is_idle_task_queued = false;
|
|
|
|
is_idle_task_queued = false;
|
|
|
|
const tasks = current_queued_idle_tasks.slice();
|
|
|
|
const tasks = queued_idle_tasks.slice();
|
|
|
|
current_queued_idle_tasks = [];
|
|
|
|
queued_idle_tasks = [];
|
|
|
|
run_all(tasks);
|
|
|
|
run_all(tasks);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param {() => void} fn
|
|
|
|
* @param {() => void} fn
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export function queue_micro_task(fn) {
|
|
|
|
export function queue_before_micro_task(fn) {
|
|
|
|
|
|
|
|
if (!is_micro_task_queued) {
|
|
|
|
|
|
|
|
is_micro_task_queued = true;
|
|
|
|
|
|
|
|
queueMicrotask(process_micro_tasks);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
queued_before_microtasks.push(fn);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @param {() => void} fn
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
export function queue_after_micro_task(fn) {
|
|
|
|
if (!is_micro_task_queued) {
|
|
|
|
if (!is_micro_task_queued) {
|
|
|
|
is_micro_task_queued = true;
|
|
|
|
is_micro_task_queued = true;
|
|
|
|
queueMicrotask(process_micro_tasks);
|
|
|
|
queueMicrotask(process_micro_tasks);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
current_queued_micro_tasks.push(fn);
|
|
|
|
queued_after_microtasks.push(fn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -47,13 +73,13 @@ export function queue_idle_task(fn) {
|
|
|
|
is_idle_task_queued = true;
|
|
|
|
is_idle_task_queued = true;
|
|
|
|
request_idle_callback(process_idle_tasks);
|
|
|
|
request_idle_callback(process_idle_tasks);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
current_queued_idle_tasks.push(fn);
|
|
|
|
queued_idle_tasks.push(fn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Synchronously run any queued tasks.
|
|
|
|
* Synchronously run any queued tasks.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export function flush_tasks() {
|
|
|
|
export function flush_after_tasks() {
|
|
|
|
if (is_micro_task_queued) {
|
|
|
|
if (is_micro_task_queued) {
|
|
|
|
process_micro_tasks();
|
|
|
|
process_micro_tasks();
|
|
|
|
}
|
|
|
|
}
|
|
|
|