Returns a promise that resolves after the specified delay.
The delay in milliseconds. Defaults to 0.
A promise that resolves after the delay.
Uses setTimeout to delay execution. When used with 0ms, it defers execution to the next macro-task, allowing the event loop to cycle.
setTimeout
await sleep(100)await sleep() // equivalent to setTimeout(..., 0) Copy
await sleep(100)await sleep() // equivalent to setTimeout(..., 0)
Returns a promise that resolves after the specified delay.