npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

setinterval-plus

v1.0.3

Published

A replacment to normal setInterval which includes pausing and resuming

Downloads

4,138

Readme

setinterval-plus

Build Status Coverage Status npm version

js-standard-style

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 callback = function () {
  console.log('Run')
}
var timer = new _setInterval(callback, 1000) // Timer starts ticking

API

timer.pause() // Pauses the interval timer
timer.resume() // Resumes the interval timer at the point where the timer was paused (+/- a few ms)
timer.stop() // Stop a timer and clears the interval
timer.start() // Start back a stoped interval with the original interval time
Example:
var _setInterval = require('setinterval-plus')

var runs = 0
var timer = new _setInterval(function () {
  console.log('Run')
  runs++
}, 100)
// console.log(timer)
setTimeout(function () {
  timer.pause()
  setTimeout(function () {
    console.log('Remaining time for Interval: ', timer.remaining) // Will print around 50
    timer.resume()
    setTimeout(function () {
      timer.stop()
      setTimeout(function () {
        timer.start()
        console.log('Remaining time for Interval: ', timer.remaining) // Will print -1 which means it restarted running
        var check = new Date()
        setTimeout(function () {
          console.log('Time before rerunning', new Date() - check)
          console.log(runs) // Should print 15
        }, 1045) // Will run 10 more times
      }, 5) // Wll Stop for 5 ms
    }, 200) // Will run for 200 ms which are 2 full runs (we have 50 ms from before)
  }, 100) // Will pause for 100 ms
}, 350) // Will run for 350 ms which are 3 full runs

Development

$ git clone [email protected]:thehobbit85/setinterval-plus.git
$ cd setinterval-plus
$ npm i
$ npm test
$ npm run coverage

License

MIT