1.0.7 • Published 5 years ago
@ircam/ticker v1.0.7
@ircam/ticker
Execute a given callback at periodic interval, trying to minimize drift and jitter.
Install
npm install [--save] @ircam/tickerUsage
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