pull/16197/head
Rich Harris 8 months ago
parent db947906f9
commit cbc227c75e

@ -27,13 +27,13 @@ function run_post_micro_tasks() {
run_all(tasks);
}
export function run_idle_tasks() {
function run_idle_tasks() {
var tasks = idle_tasks;
idle_tasks = [];
run_all(tasks);
}
export function run_micro_tasks() {
function run_micro_tasks() {
run_boundary_micro_tasks();
run_post_micro_tasks();
}
@ -70,3 +70,16 @@ export function queue_idle_task(fn) {
idle_tasks.push(fn);
}
/**
* Synchronously run any queued tasks.
*/
export function flush_tasks() {
if (boundary_micro_tasks.length > 0 || micro_tasks.length > 0) {
run_micro_tasks();
}
if (idle_tasks.length > 0) {
run_idle_tasks();
}
}

@ -27,7 +27,7 @@ import {
REACTION_IS_UPDATING,
EFFECT_ASYNC
} from './constants.js';
import { run_idle_tasks, run_micro_tasks } from './dom/task.js';
import { flush_tasks } from './dom/task.js';
import { internal_set } from './reactivity/sources.js';
import {
destroy_derived_effects,
@ -931,8 +931,7 @@ export function flush_sync(fn) {
var result = fn?.();
run_micro_tasks();
run_idle_tasks();
flush_tasks();
if (queued_root_effects.length > 0 || root_effects.length > 0) {
flush_sync();

Loading…
Cancel
Save