1.0.7 • Published 4 years ago

@ircam/ticker v1.0.7

Weekly downloads
3
License
BSD-3-Clause
Repository
github
Last release
4 years ago

@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.errorThresholdNumberThreshold 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

1.0.7

4 years ago

1.0.6

6 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago