# atomic-sleep

> Zero CPU overhead, zero dependency, true event-loop blocking sleep

Latest version **1.0.0** (published 2020-03-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install atomic-sleep
pnpm add atomic-sleep
yarn add atomic-sleep
bun add atomic-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 | 1.0.0 |
| Published | 2020-03-09 |
| First published | 2020-03-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/atomic-sleep) |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 0 |
| Unpacked size | 6.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 86 |
| Author | David Mark Clements |
| Maintainers | davidmarkclements |
| Keywords | sleep, pause, wait, performance, atomics |

## Links

- npm: https://www.npmjs.com/package/atomic-sleep
- Repository: https://github.com/davidmarkclements/atomic-sleep
- Homepage: https://github.com/davidmarkclements/atomic-sleep#readme
- Issues: https://github.com/davidmarkclements/atomic-sleep/issues
- npm.io page: https://npm.io/package/atomic-sleep

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2020-03-09

## README

<h1 align="center">Welcome to atomic-sleep ⏱️</h1>
<p>
  <img alt="Version" src="https://img.shields.io/badge/version-1.0.0-blue.svg?cacheSeconds=2592000" />
  <a href="#" target="_blank">
    <img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-yellow.svg" />
  </a>
  <a href="https://twitter.com/davidmarkclem" target="_blank">
    <img alt="Twitter: davidmarkclem" src="https://img.shields.io/twitter/follow/davidmarkclem.svg?style=social" />
  </a>
</p>

> Zero CPU overhead, zero dependency, true event-loop blocking sleep

## Usage

```js
const sleep = require('atomic-sleep')

console.time('sleep')
setTimeout(() => { console.timeEnd('sleep') }, 100) 
sleep(1000)
```

The `console.time` will report a time of just over 1000ms despite the `setTimeout`
being 100ms. This is because the event loop is paused for 1000ms and the setTimeout
fires immediately after the event loop is no longer blocked (as more than 100ms have passed).

## Install

```sh
npm install
```

## Run tests

```sh
npm test
```

## Support

Node and Browser versions that support both `SharedArrayBuffer` and `Atomics` will have (virtually) zero CPU overhead sleep. 

For Node, Atomic Sleep can provide zero CPU overhead sleep from Node 8 and up.

For browser support see https://caniuse.com/#feat=sharedarraybuffer and https://caniuse.com/#feat=mdn-javascript_builtins_atomics.


For older Node versions and olders browsers we fall back to blocking the event loop in a way that will cause a CPU spike. 



## Author

👤 **David Mark Clements (@davidmarkclem)**

* Twitter: [@davidmarkclem](https://twitter.com/davidmarkclem)
* Github: [@davidmarkclements](https://github.com/davidmarkclements)

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