//#region src/timeout/index.d.ts /** * Options for timer functions */ interface TimerOptions { /** * An optional {@link AbortSignal} to cancel the timer */ signal?: AbortSignal; } /** * Promise-based setTimeout * * Resolves with the given value after the specified delay. * * @typeParam T - The type of the resolved value * * @param delay - The delay in milliseconds. Defaults to 0 * @param value - The value to resolve with * @param options - {@link TimerOptions} * @returns A promise that resolves with the value after the delay * @throws {DOMException | unknown} When the signal is aborted * * @example * ```ts * // wait 1 second * await setTimeout(1000) * * // wait 1 second and get a value * const result = await setTimeout(1000, 'hello') * * // with abort signal * const controller = new AbortController() * await setTimeout(1000, undefined, { signal: controller.signal }) * ``` */ declare function setTimeout(delay?: number, value?: T, options?: TimerOptions): Promise; /** * Promise-based setInterval * * Yields the given value at each interval. The async generator can be * cancelled by aborting the signal or by breaking out of the loop. * * @typeParam T - The type of the yielded value * * @param delay - The interval in milliseconds. Defaults to 0 * @param value - The value to yield at each interval * @param options - {@link TimerOptions} * @returns An async generator that yields the value at each interval * * @yields {T} * * @example * ```ts * // yield every 100ms * const controller = new AbortController() * for await (const v of setInterval(100, 'tick', { signal: controller.signal })) { * console.log(v) // 'tick' * } * ``` */ declare function setInterval(delay?: number, value?: T, options?: TimerOptions): AsyncGenerator; //#endregion export { TimerOptions, setInterval, setTimeout };