@ircam/ticker

1.0.7 • Public • Published

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

Param Type Description
period Number period of the timer interval in milliseconds (floored if float is given)
callback TickerCallback callback to execute on each tick
options Object additionnal options
[options.errorThreshold] Number Threshold 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

Param Type Description
logicalTime Number logical time since start in ms
currentTime Number current time as returned by performance.now
error Number current error

License

BSD-3-Clause

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.7
    3
    • latest

Version History

Package Sidebar

Install

npm i @ircam/ticker

Weekly Downloads

3

Version

1.0.7

License

BSD-3-Clause

Unpacked Size

16.3 kB

Total Files

4

Last publish

Collaborators

  • jipodine
  • norbert.schnell
  • b-ma