Sleep for specified time.
๐ฆ Node.js,
๐ Web,
๐ Shell,
๐ Files,
๐ฐ Docs,
๐ Wiki.
sleep is a command in Unix-like operating systems that suspends program execution for specified time. This 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().
This package is available in Node.js and Web formats. To use it on the web,
simply use the extra_sleep
global variable after loading with a <script>
tag from the jsDelivr CDN.
Stability: Experimental.
const {sleep} = require('extra-sleep');
// import {sleep} from "extra-sleep";
// import {sleep} from "https://unpkg.com/extra-sleep/index.mjs"; (deno)
async function main() {
console.log('Turn on Alarm');
await sleep(1000);
console.log('Turn on Shower');
}
main();
Property | 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