Function: sleep()
sleep(
ms
:number
,signal?
:AbortSignal
):Promise
<void
>
Defined in: shared/utils/abortUtils.ts:202
Promise-based sleep function with abort support.
Parametersโ
msโ
number
Delay in milliseconds
signal?โ
Optional AbortSignal for cancellation
Returnsโ
Promise
<void
>
Promise that resolves after the delay
Remarksโ
Creates a cancelable delay that can be aborted via AbortSignal. Throws when the signal is aborted during the delay.
Exampleโ
const controller = new AbortController();
try {
await sleep(5000, controller.signal);
console.log("Delay completed");
} catch (error) {
console.log("Delay was aborted");
}
Throwsโ
When the signal is aborted