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

quickinterval

v1.1.3

Published

QuickInterval provides an easy way to create and manage intervals, with the ability to pause, resume, and adjust the delay dynamically.

Downloads

48

Readme

QuickInterval NPM version

QuickInterval is a flexible and user-friendly package for creating intervals that execute a specified callback function. It offers useful features such as pause, resume, reset, and dynamic interval delay adjustment. The class is designed to work within a Node.js environment, making it a reliable choice for your interval needs.

Features

  • Less RAM consumption because it depends on the frequency of Timeout Nodejs, which saves more memory than Interval NodeJS
  • Start and stop the interval execution
  • Pause and resume the interval execution
  • Reset the interval and start again
  • Change the interval delay dynamically
  • Get the elapsed time of the interval

Installation

Install with npm / yarn / pnpm:

npm add quickinterval
yarn add quickinterval
pnpm add quickinterval

Example Usage

import { Interval } from 'quickinterval';

const interval = new Interval(() => console.log("Interval callback"), 1000);

interval.start(); // starts the interval

setTimeout(() => {
  interval.pause(); // pauses the interval after 5 seconds
}, 5000);

setTimeout(() => {
  interval.resume(); // resumes the interval after 10 seconds
}, 10000);

setTimeout(() => {
  interval.reset(); // resets the interval after 15 seconds
}, 15000);

API

Interval Class

The Interval class is a custom implementation of an interval that provides functionality similar to the built-in setInterval method in JavaScript. However, this implementation is more efficient in terms of memory usage and provides additional methods for more flexibility.

Constructor

The Interval class constructor takes two parameters, a callback function and a delay in milliseconds. The callback function is called repeatedly after the specified delay until the interval is stopped or reset.

constructor(callback: () => void, delay: number)

Methods

start()

Starts the interval. If the interval is already running, this method does nothing.

start(): void

pause()

Pauses the interval. If the interval is already paused or stopped, this method does nothing.

pause(): void

resume()

Resumes the interval. If the interval is already running, this method does nothing.

resume(): void

reset()

Stops and resets the interval.

reset(): void

isRunning()

Returns a boolean indicating whether the interval is currently running.

isRunning(): boolean

getTimeElapsed()

Returns the elapsed time in milliseconds since the interval started.

getTimeElapsed(): number

setDelay(delay)

Sets a new delay for the interval. If the interval is running, it is restarted with the new delay.

setDelay(delay: number): void

getRemainingTime()

Returns the remaining time in milliseconds until the next interval callback.

getRemainingTime(): number

Private Method

scheduleNext()

Schedules the next interval callback and calculates the remaining time until the next callback. This method is called recursively as long as the interval is running.

private scheduleNext(): void

Sponsors

  • Love what I do? Send me some coffee !? ☕
  • Can't send coffees? Your support will help me to continue working on open-source projects like this. 🙏😇

Help

If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle nudge in the right direction, please don't hesitate to join our official Discord Server .

License

Refer to the LICENSE file.