Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@danisl99/repeat

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@danisl99/repeat

A better way to do intervals

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
3
-70%
Maintainers
1
Weekly downloads
 
Created
Source

Repeat

A better way to do intervals.

Pros

  • Repeat won't wait to the end of the first interval to run the callback. It will run it immediately.
  • You can access all the internals from inside the callback, so you can stop, change the duration or even the callback on the fly.

Install

$ npm install @danisl99/repeat

Example

const Repeat = require('@danisl99/repeat');

// Without options the it will run forever with an interval of one second
// You can stop the interval externally or internally
const exampleOne = new Repeat((self) => {
    console.log(Date.now());
    // self.stop();
})

setTimeout(() => {
    exampleOne.stop();
}, 3000);

// With options
let counterOne = 0;
const exampleTwo = new Repeat({
    duration: 10000, // or use date:(Date.now()+5000)
    interval:500,
},(self) => {
    self.endTime -= 1000; // You can change the duration internally while it runs
    if(counterOne == 2){
        // Change callback on the fly
        self.callback = ()=>{
            console.log(Date.now());
        }
    }
    console.log(counterOne);
    counterOne++;
})

Keywords

repeat

FAQs

Package last updated on 11 Jul 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts