@yocdev/timer-manager
v1.2.0
Published
Timer manager providing clean up facility.
Downloads
4
Readme
timer-manager
Timer manager providing clean up facility. Use it in App termination to avoid keeping event loop active.
Installation
$ npm install @yocdev/timer-manager
Usage
// Since we'll replace the global timer functions (e.g. setTimeout, setInterval ...)
// in order to trace them, require the package as early as possible.
require('@yocdev/timer-manager')
// In your codes, just use the timer functions as before.
setTimeout(...)
setInterval(...)
clearTimeout(...)
clearInterval(...)
// In your App termination process, clear all still active timers
// to avoid keeping event loop active.
const TimerManager = require('@yocdev/timer-manager')
TimerManager.clearAll()
// If you wanna access the original timer functions, use TimerManager.original.
// Note: These timer functions are not managed by TimerManager,
// `TimerManager.clearAll()` can't clear them.
// You have to clear them yourself.
TimerManager.original.setTimeout(...)
TimerManager.original.setInterval(...)
TimerManager.original.clearTimeout(...)
TimerManager.original.clearInterval(...)