Utilities
Timers
Wait, cancel, and enforce deadlines on asynchronous operations.
Timers
sleep()
import { sleep } from 'oruntime'
await sleep(500)
The duration is measured in milliseconds and must be finite and non-negative. Invalid values throw RangeError.
Cancel a delay
const controller = new AbortController()
const waiting = sleep(10_000, { signal: controller.signal })
controller.abort('Cancelled by the user')
await waiting // throws OperationAbortedError
The cancellation reason is preserved in error.cause.
withTimeout()
const value = await withTimeout(loadConfiguration(), 2_000)
If the promise does not settle before the deadline, the returned promise rejects with TimeoutError.
await withTimeout(operation, 1_000, {
message: 'The operation took too long'
})
withTimeout() cannot cancel the original promise; it only stops waiting for it. Pass an AbortSignal to cancellable operations. Values and errors from the original promise are forwarded unchanged.
The timers capability is true when global setTimeout and clearTimeout functions exist.