gytimer
v2.0.0
Published
Correction of the work of the usual function 'setTimeout' and the addition of new functionality
Downloads
14
Readme
What does that package?
- Fixes issues with the event loop's native setTimeout function.
- Adds a new asynchronous function "sleep".
- Does not clog event loop, but speeds it up
Installation
$ npm install gytimer
Usage
For more detailed information on how to use this module, I recommend using: npm run test
import { setCustomTimeout, clearCustomTimeout, sleep } from 'gytimer'
/**
* Get the current Unix time
*/
const timestamp = Date.now()
/**
* Clear timeout example
* Outputs: nothing
*/
const purifiedCustomTimeout = setCustomTimeout(() => {
console.log('This timeout will purify 😰')
}, 1000)
clearCustomTimeout(purifiedCustomTimeout)
/**
* Execution timeout example
* Outputs: This timeout will execute successful for 1041 ms 😇
*/
setCustomTimeout (() => {
console.log(`This timeout will execute successful for ${Date.now() - timestamp} ms 😇`)
}, 1000)
/**
* Sleep function example
* @param {number} duration
*/
async function testSleep (duration) {
let sleepStart = Date.now()
for (let key in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) {
await sleep(duration)
console.log(key)
}
console.log(`Log after sleep has sent (${Date.now() - sleepStart}) 😇`)
}
testSleep(2000)
Credits
sha512boo
License
ISC