|
|
|
@ -38,6 +38,7 @@ let current_scheduler_mode = FLUSH_MICROTASK;
|
|
|
|
|
// Used for handling scheduling
|
|
|
|
|
let is_micro_task_queued = false;
|
|
|
|
|
let is_task_queued = false;
|
|
|
|
|
let is_raf_queued = false;
|
|
|
|
|
// Used for $inspect
|
|
|
|
|
export let is_batching_effect = false;
|
|
|
|
|
|
|
|
|
@ -52,7 +53,7 @@ let current_queued_effects = [];
|
|
|
|
|
/** @type {Array<() => void>} */
|
|
|
|
|
let current_queued_tasks = [];
|
|
|
|
|
/** @type {Array<() => void>} */
|
|
|
|
|
let current_queued_microtasks = [];
|
|
|
|
|
let current_raf_tasks = [];
|
|
|
|
|
let flush_count = 0;
|
|
|
|
|
// Handle signal reactivity tree dependencies and consumer
|
|
|
|
|
|
|
|
|
@ -586,11 +587,6 @@ function flush_queued_effects(effects) {
|
|
|
|
|
|
|
|
|
|
function process_microtask() {
|
|
|
|
|
is_micro_task_queued = false;
|
|
|
|
|
if (current_queued_microtasks.length > 0) {
|
|
|
|
|
const tasks = current_queued_microtasks.slice();
|
|
|
|
|
current_queued_microtasks = [];
|
|
|
|
|
run_all(tasks);
|
|
|
|
|
}
|
|
|
|
|
if (flush_count > 101) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -637,6 +633,13 @@ function process_task() {
|
|
|
|
|
run_all(tasks);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function process_raf_task() {
|
|
|
|
|
is_raf_queued = false;
|
|
|
|
|
const tasks = current_raf_tasks.slice();
|
|
|
|
|
current_raf_tasks = [];
|
|
|
|
|
run_all(tasks);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {() => void} fn
|
|
|
|
|
* @returns {void}
|
|
|
|
@ -653,12 +656,12 @@ export function schedule_task(fn) {
|
|
|
|
|
* @param {() => void} fn
|
|
|
|
|
* @returns {void}
|
|
|
|
|
*/
|
|
|
|
|
export function schedule_microtask(fn) {
|
|
|
|
|
if (!is_micro_task_queued) {
|
|
|
|
|
is_micro_task_queued = true;
|
|
|
|
|
queueMicrotask(process_microtask);
|
|
|
|
|
export function schedule_raf_task(fn) {
|
|
|
|
|
if (!is_raf_queued) {
|
|
|
|
|
is_raf_queued = true;
|
|
|
|
|
requestAnimationFrame(process_raf_task);
|
|
|
|
|
}
|
|
|
|
|
current_queued_microtasks.push(fn);
|
|
|
|
|
current_raf_tasks.push(fn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -721,8 +724,8 @@ export function flushSync(fn) {
|
|
|
|
|
if (current_queued_pre_and_render_effects.length > 0 || effects.length > 0) {
|
|
|
|
|
flushSync();
|
|
|
|
|
}
|
|
|
|
|
if (is_micro_task_queued) {
|
|
|
|
|
process_microtask();
|
|
|
|
|
if (is_raf_queued) {
|
|
|
|
|
process_raf_task();
|
|
|
|
|
}
|
|
|
|
|
if (is_task_queued) {
|
|
|
|
|
process_task();
|
|
|
|
|