This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

timers-classes
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

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);

Readme

Keywords

Package Sidebar

Install

npm i timers-classes

Weekly Downloads

1

Version

1.0.2

License

ISC

Unpacked Size

19.2 kB

Total Files

16

Last publish

Collaborators

  • sid-max1996