ss

sleep-synchronously

Block the main thread for a given amount of time

Showing:

Popularity

Downloads/wk

48

GitHub Stars

105

Maintenance

Last Commit

5mos ago

Contributors

1

Package

Dependencies

0

Size (min+gzip)

0.2KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

sleep-synchronously

Block the main thread for a given amount of time

This is similar to a native sleep() function you can find in many other languages.

This is the wrong tool for most tasks! Prefer using async APIs whenever possible. This package can be useful in tests if you need to wait on some resource, for example, where you know it only takes 1 second but there's no good way to detect when it's ready.

This package is better than many other similar packages as it's not a native Node.js addon, but instead uses modern JavaScript features. It does not work in the browser.

Install

$ npm install sleep-synchronously

Usage

import sleepSynchronously from 'sleep-synchronously';

console.log(new Date());
//=> Sun Aug 16 2020 14:28:54 GMT+0200 (Central European Summer Time)

sleepSynchronously(2000);

console.log(new Date());
//=> Sun Aug 16 2020 14:28:56 GMT+0200 (Central European Summer Time)

API

sleepSynchronously(milliseconds)

Block the main thread for the given amount of milliseconds.

No other code will execute while it's sleeping, not even asynchronous code.

  • delay - Delay a promise a given amount of time
  • make-synchronous - Make an asynchronous function synchronous

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100