Skip to content

About

Synchronous and asynchronous sleep methods.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

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().

This package also provides a command line tool xsleep -- with a similar behaviour as sleep -- that can be used to sleep for specified time in seconds, minutes, hours, or days. Please check examples below. It should be noted small delays (few milliseconds) are not accurate.

▌ 📦 JSR, 📦 NPM, 📰 Docs.


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!

# Install CLI tool
$ deno install --global --name xsleep jsr:@nodef/extra-sleep/bin.ts

# Sleep for 0.1 seconds
$ xsleep 0.1

# Sleep for 1.23 minutes
$ xsleep 1.23m

# Sleep for 1 day 23 hours
$ xsleep 1d 23h


Index

Name Description
sleep Sleep for specified time (async).
sleepSync Sleep for specified time.

$ xsleep <number>[unit] ... | [option]

# Units:
# s: sleep for number seconds.
# m: sleep for number minutes.
# h: sleep for number hours.
# d: sleep for number days.

# Options:
# --help: get help
# --version: get version details


References




ORG

About

Synchronous and asynchronous sleep methods.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Used by

Contributors

Languages