API reference@evolu/commonTask › yieldNow

const yieldNow: Task<void>;

Defined in: packages/common/src/Task.ts:4821

Yields execution to the host scheduler.

Uses native scheduler.yield() when available, setImmediate when available, and setTimeout elsewhere. Because this is a Task, await run(yieldNow) is an explicit abortable checkpoint and is visible in Run monitoring.

For example, call it periodically in a long-running synchronous loop to let the host process rendering, input, and other scheduled work.

Example

import { assertOk, createRun, ok, yieldNow, type Task } from "@evolu/common";

const sumTo =
  (count: number): Task<number> =>
  async (run) => {
    let sum = 0;

    for (let index = 0; index < count; index++) {
      if (index > 0 && index % 1000 === 0) await run.ok(yieldNow);
      sum += index;
    }

    return ok(sum);
  };

await using run = createRun();
assertOk(await run(sumTo(1001)), 500500);