UNPKG

remix-utils-rt

Version:

This package contains simple utility functions to use with [React Router](https://reactrouter.com/home).

26 lines 842 B
import { setTimeout } from "node:timers/promises"; /** * Get an async iterable that yields on an interval until aborted. * @param ms The amount of time to wait between intervals, in milliseconds * @param options The options for the timer * @returns An async iterable that yields on each intervals * @example * let controller = new AbortController(); * for await (let _ of interval(1000, { signal: controller.signal })) { * // Do something every second until aborted * } */ export async function* interval(ms, options) { let signal = options?.signal ?? new AbortSignal(); while (!signal.aborted) { try { yield await setTimeout(ms, void 0, { signal }); } catch { return; } } } export class TimersError extends globalThis.Error { } //# sourceMappingURL=timers.js.map