createNodeScheduler provides sleep, timeout, and retry utilities with AbortSignal support for Node.js async workflows.
// Source: https://github.com/ThinkInAIXYZ/deepchat | 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.
import { setTimeout as delay } from 'node:timers/promises'
export interface SleepInput {
ms: number
reason: string
signal?: AbortSignal
}
export interface TimeoutInput<T> {
task: Promise<T>
ms: number
reason: string
signal?: AbortSignal
}
export interface RetryInput<T> {
task: () => Promise<T>
maxAttempts: number
initialDelayMs: number
backoff: number
reason: string
signal?: AbortSignal
}
export interface Scheduler {
sleep(input: SleepInput): Promise<void>
timeout<T>(input: TimeoutInput<T>): Promise<T>
retry<T>(input: RetryInput<T>): Promise<T>
}
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key