From bce557cc2dc767628bed6aac87301a1be7c5431b Mon Sep 17 00:00:00 2001 From: rxliuli Date: Tue, 4 Nov 2025 05:03:50 +0800 Subject: init commit --- node_modules/svelte/src/runtime/internal/loop.js | 45 ++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 node_modules/svelte/src/runtime/internal/loop.js (limited to 'node_modules/svelte/src/runtime/internal/loop.js') diff --git a/node_modules/svelte/src/runtime/internal/loop.js b/node_modules/svelte/src/runtime/internal/loop.js new file mode 100644 index 0000000..5a14565 --- /dev/null +++ b/node_modules/svelte/src/runtime/internal/loop.js @@ -0,0 +1,45 @@ +import { raf } from './environment.js'; + +const tasks = new Set(); + +/** + * @param {number} now + * @returns {void} + */ +function run_tasks(now) { + tasks.forEach((task) => { + if (!task.c(now)) { + tasks.delete(task); + task.f(); + } + }); + if (tasks.size !== 0) raf(run_tasks); +} + +/** + * For testing purposes only! + * @returns {void} + */ +export function clear_loops() { + tasks.clear(); +} + +/** + * Creates a new task that runs on each raf frame + * until it returns a falsy value or is aborted + * @param {import('./private.js').TaskCallback} callback + * @returns {import('./private.js').Task} + */ +export function loop(callback) { + /** @type {import('./private.js').TaskEntry} */ + let task; + if (tasks.size === 0) raf(run_tasks); + return { + promise: new Promise((fulfill) => { + tasks.add((task = { c: callback, f: fulfill })); + }), + abort() { + tasks.delete(task); + } + }; +} -- cgit v1.2.3