Abort-aware sleep utility for async operations and rate limiting backoff.
// Source: https://github.com/griffinwork40/agent-afk | 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. /** * Provider-neutral abort-aware sleep helper. * * Resolves immediately when `signal` is already aborted; otherwise waits * `ms` milliseconds, resolving early if the signal fires while sleeping. * Invariant: the timer is ref'd. An awaited backoff IS pending work: a * one-shot `afk chat` waiting out a connection outage has no other ref'd * handle, and an unref'd timer let the event loop drain so the process * exited 0 mid-retry with no output (observed 2026-10-06, sprint Lane V). * Abort clears the timer, so cancellation never waits it out. * * Previously duplicated ve ... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key