Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

timers-classes

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

timers-classes

Timer classes for different tasks

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

timers-classes

Usage

Timer classes for easy creation and use. It is possible to restart an already running timer, start the timer again after the end. It is possible to loop the start of timers and set the maximum number of repetitions.

Timer classes

All possible constructors params:

callback {Function} - callback function
time {number} - timer time
repeatCount {number=0} - number of additional repetitions
waitAsyncCallback {boolean=true} - wait async callback after start timer again
start {boolean=false} - start timer after creation

Timer example:

import { Timer } from 'timers-classes';
const timer = new Timer(() => {
  console.log('worked');
}, 100);
timer.start();
import { TimerBuilder } from 'timers-classes';

const timer = TimerBuilder.create(() => {
    console.log('worked');
  }, 100)
  .setStartImmediately(true)
  .build();

LoopTimer example:

import { LoopTimer } from 'timers-classes';

let workCount = 0;
const timer = new LoopTimer(() => {
  console.log('workCount', workCount++);
  if (workCount === 5) {
    timer.stop();
  }
}, 100);
timer.start();
import { TimerBuilder } from 'timers-classes';

let workCount = 0;
const timer = TimerBuilder.create(() => {
    console.log('workCount', workCount++);
  }, 100)
  .setStartImmediately(true)
  .buildLoop();
setTimeout(() => {
  timer.stop();
}, 1000);

RepeatingTimer example:

import { RepeatingTimer } from 'timers-classes';

let workCount = 0;
const timer = new RepeatingTimer(() => {
  workCount += 1;
  if (timer.remainingRepeatCount === 0) {
    console.log('result workCount', workCount);
  }
}, 100, 3);
timer.start();
import { TimerBuilder } from 'timers-classes';

let workCount = 0;
const timer = TimerBuilder.create(() => {
    console.log('workCount', workCount++);
    if (workCount === 3) {
      timer.stop();
    }
  }, 100)
  .setStartImmediately(true)
  .buildRepeating(5);

Keywords

timers

FAQs

Package last updated on 16 Feb 2022

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