Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@ircam/ticker

Package Overview
Dependencies
Maintainers
4
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ircam/ticker

Execute a given callback at periodic interval, trying to minimize drift and jitter

latest
Source
npmnpm
Version
1.0.7
Version published
Maintainers
4
Created
Source

@ircam/ticker

Execute a given callback at periodic interval, trying to minimize drift and jitter.

Install

npm install [--save] @ircam/ticker

Usage

import Ticker from '@ircam/ticker'

const period = 50; // in milliseconds
const ticker = new Ticker(period, (logicalTime, currentTime, error) => {
  console.log(logicalTime, currentTime, error);
});

ticker.start();

API

Ticker

Precise periodic timer (based on setTimeout) that monitor and adapt itself to stay close to the given therical period. In particular, try to minimize the drift caused by the use of a raw setTimeout. Observed average jitter is around +/- 2ms.

Kind: global class

new Ticker(period, callback, options)

ParamTypeDescription
periodNumberperiod of the timer interval in milliseconds (floored if float is given)
callbackTickerCallbackcallback to execute on each tick
optionsObjectadditionnal options
[options.errorThreshold]NumberThreshold error where the timer considers itself as out of bounds. Increasing this value tends to increase the overall jitter.

ticker.period : Number

Period of the timer. Must be an integer, the given value is floored. When updated the new value is applied at the next tick.

Kind: instance property of Ticker

ticker.start()

Start the ticker instance.

Kind: instance method of Ticker

ticker.stop()

Stop the ticker instance.

Kind: instance method of Ticker

TickerCallback : function

Kind: global typedef

ParamTypeDescription
logicalTimeNumberlogical time since start in ms
currentTimeNumbercurrent time as returned by performance.now
errorNumbercurrent error

License

BSD-3-Clause

Keywords

utility

FAQs

Package last updated on 22 May 2020

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