2.0.0 • Published 2 years ago

gytimer v2.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

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

1.2.9

2 years ago

2.0.0

2 years ago

1.2.8

2 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago