sgb004-timer
v1.0.4
Published
Timer
Readme
Timer
This is a class that allows you to create a simple timer in JavaScript. You can use this class to execute a callback function periodically after a specified time interval.
Installation
To install the Timer you can use npm:
npm i sgb004-timerUsage
To use it, simply create a new Timer instance passing in the callback function, interval in milliseconds, and optionally an initial delay:
const timer = new Timer(() => { console.log('¡Hola!'); }, 1000, 5000);This will execute the callback function every second, after an initial 5 seconds delay.
Then to start the timer, call the start() method:
timer.start();And to stop it, use stop():
timer.stop();You can also restart the timer with reset():
timer.reset();API
Constructor
callback- Function to execute on each interval.time- (Optional) Interval in milliseconds.delay- (Optional) Initial delay in milliseconds before starting.
Methods
start()- Starts the timer execution.stop()- Stops the timer.reset()- Restarts the timer.
Author
License
MIT
