TypeScript · correctness
no-hand-rolled-sleep
eslint:no-hand-rolled-sleep Disallow uncancellable promisified timers and timeout arms.
- Default
- error
- Fix
- none
- Languages
- typescript
Why
A timer that outlives an aborted operation or a lost promise race retains work and can keep the process alive until it fires.
Fix
Use `node:timers/promises` with an abort signal for delays, or pass `AbortSignal.timeout(...)` to the timed operation.
Before / after
Executed by this rule’s unit tests.
Before
A Promise wraps a timer without cancellation
await new Promise((resolve) => setTimeout(resolve, 500)); After
A standard-library timer accepts an abort signal
import { setTimeout as sleep } from "node:timers/promises";
await sleep(500, undefined, { signal }); Limits
- The rule skips tests, scripts, generated files, and client modules by default, and supports explicit path exemptions.
Message IDs
handRolledSleephandRolledTimeoutRace