A simple cancellable timer.
No dependencies and uses setTimeout
under the hood.
npm i @art-of-coding/timer
import createTimer from '@art-of-coding/timer'
// create a timer for 60 seconds from now
const timer = createTimer(60 * 1000)
// add a listener
timer.on(() => {
console.log('Timer fired')
})
// cancel the timer
timer.cancel()
// reset the timer and set for 50 seconds
timer.reset(50 * 1000)
Copyright 2020 Art of Coding.
This software is licensed under the MIT License.