All files / src/internal/client/dom task.js

55.55% Statements 20/36
33.33% Branches 1/3
33.33% Functions 1/3
54.28% Lines 19/35

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 362x 2x 2x 2x 2x 2x 2x 2x 2x 2x             2x             2x 2x 2x 2x 2x 12408x     12408x     12408x  
import { run_all } from '../../shared/utils.js';
 
let is_task_queued = false;
let is_raf_queued = false;
 
/** @type {Array<() => void>} */
let current_queued_tasks = [];
/** @type {Array<() => void>} */
let current_raf_tasks = [];
 
function process_task() {
	is_task_queued = false;
	const tasks = current_queued_tasks.slice();
	current_queued_tasks = [];
	run_all(tasks);
}
 
function process_raf_task() {
	is_raf_queued = false;
	const tasks = current_raf_tasks.slice();
	current_raf_tasks = [];
	run_all(tasks);
}
 
/**
 * Synchronously run any queued tasks.
 */
export function flush_tasks() {
	if (is_task_queued) {
		process_task();
	}
	if (is_raf_queued) {
		process_raf_task();
	}
}