no idea what a 'boundary micro task' is or why it was deemed necessary but evidently it isn't

pull/15844/head
Rich Harris 3 months ago
parent 70a01fc9b1
commit 36a90594ce

@ -6,22 +6,13 @@ const request_idle_callback =
? (/** @type {() => void} */ cb) => setTimeout(cb, 1) ? (/** @type {() => void} */ cb) => setTimeout(cb, 1)
: requestIdleCallback; : requestIdleCallback;
/** @type {Array<() => void>} */
let boundary_micro_tasks = [];
/** @type {Array<() => void>} */ /** @type {Array<() => void>} */
let micro_tasks = []; let micro_tasks = [];
/** @type {Array<() => void>} */ /** @type {Array<() => void>} */
let idle_tasks = []; let idle_tasks = [];
function run_boundary_micro_tasks() { function run_micro_tasks() {
var tasks = boundary_micro_tasks;
boundary_micro_tasks = [];
run_all(tasks);
}
function run_post_micro_tasks() {
var tasks = micro_tasks; var tasks = micro_tasks;
micro_tasks = []; micro_tasks = [];
run_all(tasks); run_all(tasks);
@ -33,29 +24,13 @@ function run_idle_tasks() {
run_all(tasks); run_all(tasks);
} }
function run_micro_tasks() { export { queue_micro_task as queue_boundary_micro_task };
run_boundary_micro_tasks();
run_post_micro_tasks();
}
/**
* @param {() => void} fn
*/
export function queue_boundary_micro_task(fn) {
if (boundary_micro_tasks.length === 0 && micro_tasks.length === 0) {
queueMicrotask(run_micro_tasks);
}
// TODO do we need to differentiate between `boundary_micro_tasks` and `micro_tasks`?
// nothing breaks if we push everything to `micro_tasks`
boundary_micro_tasks.push(fn);
}
/** /**
* @param {() => void} fn * @param {() => void} fn
*/ */
export function queue_micro_task(fn) { export function queue_micro_task(fn) {
if (boundary_micro_tasks.length === 0 && micro_tasks.length === 0) { if (micro_tasks.length === 0) {
queueMicrotask(run_micro_tasks); queueMicrotask(run_micro_tasks);
} }
@ -77,7 +52,7 @@ export function queue_idle_task(fn) {
* Synchronously run any queued tasks. * Synchronously run any queued tasks.
*/ */
export function flush_tasks() { export function flush_tasks() {
if (boundary_micro_tasks.length > 0 || micro_tasks.length > 0) { if (micro_tasks.length > 0) {
run_micro_tasks(); run_micro_tasks();
} }

Loading…
Cancel
Save