Event Loop Task Scheduler (utils/schedule-task.ts)

marimo · frontend/src/utils/schedule-task.ts · typescript · Apache-2.0
infra, automation, lang:javascript, lang:typescript, tag:performance, tag:event-loop

Schedules a callback to run as a fresh task after the current one, yielding to the browser via scheduler.postTask, MessageChannel, or setTimeout fallback.

// Source: https://github.com/marimo-team/marimo | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
/* Copyright 2026 Marimo. All rights reserved. */
/**
 * Schedules `callback` to run as a fresh task once the current task finishes,
 * letting the browser paint and handle input in between. Used to spread heavy
 * work across the event loop instead of blocking it in one long task.
 */
export type ScheduleTaskFn = (callback: () => void) => void;

/**
 * Picks the best available "yield to the event loop" primitive, preferring
 * ones that impose no artificial delay between tasks:
 *
 * 1. `scheduler.postTask` — the purpose-built Prioritized Task Scheduling API.
 *    `user-visible` runs

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key