sleep is a command in Unix-like operating systems that suspends program execution for specified time. This package provides both a synchronous and an asynchronous method for sleeping without doing a busy wait. The synchronous sleep is achieved using Atomics.wait() (1), and the asynchronous one is achived using Promisified setTimeout().
import {sleep, sleepSync} from "jsr:@nodef/extra-sleep";
console.log('Turn on Alarm');
await sleep(1000);
console.log('Turn on Shower');
sleepSync(1e+6); // And relax!
Name | Description |
---|---|
sleep | Sleep for specified time (async). |
sleepSync | Sleep for specified time. |
- Sleep (Unix): Wikipedia
- sleep package by Erik Dubbelboer
- setTimeout(): MDN Web docs
- Atomics.wait(): MDN Web docs