rolex

Drift-minimizing setInterval replacement and high-precision timer utility for Node and browser

MIT 6 个版本
安装
npm install rolex
yarn add rolex
pnpm add rolex
bun add rolex
README

rolex rolex on npm build status

Drift-minimizing setInterval replacement and high-precision timer utility for Node and browser

Comparison between setInterval, rolex, and recursive setTimeout

How it works

To ensure maximal accuracy compared with setTimeout, Rolex calls setTimeout in advance of the requested timeout, then checks how close the requested timeout is. It does this recursively until the timeout is reached within a given threshold. Both the aggression and threshold are user-configurable.

Installation

In Node: npm install rolex

In browser:

  1. Copy rolex.js or rolex.min.js (with optional source map at rolex.min.js.map)
  2. <script src="path/to/rolex.{min.}js"></script>
  3. setInterval and clearInterval are automatically replaced -- if this is undesired, Rolex.noConflict();

Usage

var Rolex = require('rolex')
var r = Rolex(10, () => {
  console.log('executes in 10 ms')
}).start()

More examples in test/rolex.js.

版本列表
1.1.2 2017-10-20
1.1.1 2017-10-20
1.1.0 2017-10-20
1.0.0 2016-04-12
0.0.1 2015-01-10
0.0.0 2015-01-10