npm i @avanio/sleep
await sleep(1000); // plain sleep
const controller = new AbortController();
await sleep(1000, {signal: controller.signal}); // sleep with abort signal
await sleep(1000, {signal: controller.signal, abortThrows: true}); // sleep with abort signal and throws SleepAbortError when aborted
if adding abortThrows option true, it will throw SleepAbortError
instance when aborted
const res = await sleepResult(1000); // plain sleep
const controller = new AbortController();
const res = await sleepResult(1000, {signal: controller.signal}); // sleep with abort signal
if (res.isErr) {/* something was wrong on arguments */}
const res = await sleepResult(1000, {signal: controller.signal, abortThrows: true}); // sleep with abort signal and throws SleepAbortError when aborted
if (res.isErr) {/* something was wrong on arguments or have aborted with SleepAbortError */}