Step, loop & sleep methods
$ npm install sleepover
const { sleep, over, snooze } = require('sleepover')
sleep(500)
//=> delays execution for 500ms using Atomics.wait
over(30, (i) => console.log(i))
//=> loops 30 times, calling the provided method each time
async function something() {
await snooze(500)
//=> delays execution for 500ms using async/await + Promise + setTimeout
}
Type: number
The number, in ms, that you'd like to delay execution of your code. (utilizes the Atomics
API under the hood)
Type: number
The number of times you would like to loop/iterate.
Type: function
The callback function you want executed on each iteration (it gets provided a single index argument).
Type: number
The number, in ms, that you'd like to delay execution of your code. (utilizes a Promise
+ setTimeout
)
Type: boolean
Result of the test conditions for defining Atomics
support in the current environment. Use this to determine whether ot use sleep
or snooze
respectively.
MIT © Darcy Clarke