0.1.1 • Published 2 years ago
@gallofeliz/timer v0.1.1
Timer
Note: This module is part of @gallofeliz/js-libs that is a personal project. It is not developed nor tested for applications that need high security or scalability.
Timer component:
- Start/stoppable
- Fn callback
- resetable (the counter)
- Max delay
- Abortable
- Error handling (callback/log/event)
- Events
import { Timer } from '@gallofeliz/timer'
const timer = new Timer({
fn() {
console.log('Do the job !')
},
delay: 100,
maxDelayUntilStop: 250
})
const abortController = new AbortController
timer.start(abortController.signal)
await setTimeout(50)
timer.reset()
// Here if I do too much reset(), the timer will trigger timeout after 250ms that is the max
// But if abort the AbortController or call timer.stop(), the timer stop and the job will not been done !
await setTimeout(110)
console.log('Job done !')
0.1.1
2 years ago