gytimer

2.0.0 • Public • Published
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

Package Sidebar

Install

npm i gytimer

Weekly Downloads

0

Version

2.0.0

License

ISC

Unpacked Size

7.56 kB

Total Files

9

Last publish

Collaborators

  • sha512boo