Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/darcyclarke/sleepover
💤 Sleep, snooze & step methods
https://github.com/darcyclarke/sleepover
await block delay for iterate javascript loop nodejs sleep sync while
Last synced: 13 days ago
JSON representation
💤 Sleep, snooze & step methods
- Host: GitHub
- URL: https://github.com/darcyclarke/sleepover
- Owner: darcyclarke
- License: mit
- Created: 2018-03-13T20:06:15.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-02-07T12:12:44.000Z (almost 3 years ago)
- Last Synced: 2024-08-08T15:47:25.465Z (3 months ago)
- Topics: await, block, delay, for, iterate, javascript, loop, nodejs, sleep, sync, while
- Language: JavaScript
- Homepage: https://npmjs.com/package/sleepover
- Size: 51.8 KB
- Stars: 18
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# sleepover ![Tests](https://github.com/darcyclarke/sleepover/actions/workflows/run_tests.yml/badge.svg)
> Step, loop & sleep methods
![](https://media.giphy.com/media/nGMyNVfRAsgA8/giphy.gif)
## Install
```
$ npm install sleepover
```## Usage
```js
const { sleep, over, snooze } = require('sleepover')sleep(500)
//=> delays execution for 500ms using Atomics.waitover(30, (i) => console.log(i))
//=> loops 30 times, calling the provided method each timeasync function something() {
await snooze(500)
//=> delays execution for 500ms using async/await + Promise + setTimeout
}
```## API
### sleep(delay)
#### delay
Type: `number`
The number, in ms, that you'd like to delay execution of your code. (utilizes the [`Atomics`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics) API under the hood)
### over(times, callback)
#### times
Type: `number`
The number of times you would like to loop/iterate.
#### callback
Type: `function`
The callback function you want executed on each iteration (it gets provided a single index argument).
### snooze(delay)
#### delay
Type: `number`
The number, in ms, that you'd like to delay execution of your code. (utilizes a `Promise` + `setTimeout`)
### atomics
Type: `boolean`
Result of the test conditions for defining [`Atomics`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics) support in the current environment. Use this to determine whether ot use `sleep` or `snooze` respectively.
## License
MIT © [Darcy Clarke](http://darcyclarke.me)