New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

interval-loop-manager

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

interval-loop-manager

A Manager deals interval loops.

latest
Source
npmnpm
Version
1.1.1
Version published
Maintainers
1
Created
Source

Interval Loop Manager

A class to manage a loop with some interval.

Purpose

I want set a loop with some interval.

Sometimes, I want to stop the loop or change the interval.

How to use

Setup

Require interval-loop-manager.

const IntervalLoopManager = require('interval-loop-manager')

I explain interval loop manager by setting a loop of the following function.

const yourFunction = () => {
  // some process
}

Start a loop

In case you want to set loop with 5 seconds interval.

const managedLoop =
  new IntervalLoopManager(
    yoruFunction,
    { interval: 5000 }
  )

or

var managedLoop = new IntervalLoopManager( yourFunction )
managedLoop.start({ interval: 5000 })

Stop the loop

managedLoop.stop()

Restart the loop

managedLoop.restart()

or

managedLoop.start()

Change the interval

Ways to change the interval to 7 seconds.

In case you want to change it as soon as possible.

managedLoop.restart({ interval: 7000 })

In case you allow current loop to finish.

managedLoop.assignValues({ interval: 7000 })

Detect whether the loop is running or not

if ( managedLoop.isRunning() ) {
  console.log('Loop is running.')
} else {
  console.log('Loop is not running.')
}

License

MIT

Reference

http://stackoverflow.com/questions/1280263/changing-the-interval-of-setinterval-while-its-running

Keywords

interval

FAQs

Package last updated on 30 Jun 2017

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