setinterval-plus
setinterval-plus is inspired by the stackoverflow answer on how to pause and resume normal setInterval timers. What setinterval-plus provides is a smiliar API as the vanila function setIntreval only the object returned isn't a Timer but instead it returns and object with the ability to start/pause/resume/stop the Timer object with a very intuitive and foolproof API.
Installation
$ npm i setinterval-plus
Create a new setinterval-plus
After creating a new instance the timer will start running.
Params:
- callback - The function to be called on each setInterval iteration. Can't take any args since the function will be called like this: callback()
- interval - Time in ms to wait between intervals
Example:
var { console}var timer = callback 1000 // Timer starts ticking
API
timer // Pauses the interval timertimer // Resumes the interval timer at the point where the timer was paused (+/- a few ms)timer // Stop a timer and clears the intervaltimerstart // Start back a stoped interval with the original interval time
Example:
var _setInterval = var runs = 0var timer = { console runs++} 100// console.log(timer) // Will run for 350 ms which are 3 full runs
Development
$ git clone git@github.com:thehobbit85/setinterval-plus.git$ cd setinterval-plus$ npm i$ npm test$ npm run coverage
License
MIT