# sleep

> Add sleep() and usleep() to nodejs

Latest version **6.3.0** (published 2020-07-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install sleep
pnpm add sleep
yarn add sleep
bun add sleep
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 6.3.0 |
| Published | 2020-07-13 |
| First published | 2012-03-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/sleep) |
| Module format | CommonJS |
| Node | >=0.8.0 |
| Dependencies | 1 |
| Unpacked size | 10.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 450 |
| Author | Erik Dubbelboer |
| Maintainers | erikdubbelboer |
| Keywords | sleep, usleep |

## Links

- npm: https://www.npmjs.com/package/sleep
- Repository: https://github.com/erikdubbelboer/node-sleep
- Homepage: http://github.com/erikdubbelboer/node-sleep
- Issues: https://github.com/erikdubbelboer/node-sleep/issues
- npm.io page: https://npm.io/package/sleep

## Dependencies (1)

- [nan](https://npm.io/package/nan.md) ^2.14.1

## Recent versions

- 6.3.0 (latest) — 2020-07-13
- 6.2.0 — 2020-05-18
- 6.1.0 — 2019-05-07
- 6.0.0 — 2019-01-26
- 5.2.4 — 2019-01-13
- 5.2.3 — 2018-07-31
- 5.2.2 — 2018-07-30
- 5.1.1 — 2017-04-08
- 5.1.0 — 2017-01-10
- 5.0.0 — 2016-11-12
- 4.0.0 — 2016-09-07
- 3.0.1 — 2016-02-03
- 3.0.0 — 2015-07-31
- 2.0.0 — 2015-02-07
- 1.2.0 — 2014-12-04
- … 12 more at https://npm.io/package/sleep/versions

## README

[![Build Status](https://travis-ci.org/erikdubbelboer/node-sleep.png?branch=master)](https://travis-ci.org/erikdubbelboer/node-sleep)
[![Build status](https://ci.appveyor.com/api/projects/status/09kubqqykjaxdrab?svg=true)](https://ci.appveyor.com/project/erikdubbelboer/node-sleep)
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Ferikdubbelboer%2Fnode-sleep.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Ferikdubbelboer%2Fnode-sleep?ref=badge_shield)

sleep
=====

Add [`sleep()`][1], `msleep()` and [`usleep()`][2] to Node.js, via a C++ binding.

This is mainly useful for debugging.

Note that because this is a C++ module, it will need to be built on the system you are going to use it on.

These calls will block execution of all JavaScript by halting Node.js' event loop!
==================================================================================

Alternative
-----------

When using nodejs `9.3` or higher it's better to use [Atomics.wait](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait) which doesn't require compiling this C++
module.
The `sleep` and `msleep` functions can be implemented like this:
```js
function msleep(n) {
  Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, n);
}
function sleep(n) {
  msleep(n*1000);
}
```
If you require `usleep` this module is still required.

Usage
-----

    var sleep = require('sleep');

* `sleep.sleep(n)`: sleep for `n` seconds
* `sleep.msleep(n)`: sleep for `n` miliseconds
* `sleep.usleep(n)`: sleep for `n` microseconds (1 second is 1000000 microseconds)


[1]: http://linux.die.net/man/3/sleep
[2]: http://linux.die.net/man/3/usleep


## License
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Ferikdubbelboer%2Fnode-sleep.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Ferikdubbelboer%2Fnode-sleep?ref=badge_large)

---
_Source: https://npm.io/package/sleep · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
