Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pakastin/clocktick
Clock-accurate timeout for Node.js and browser
https://github.com/pakastin/clocktick
Last synced: 11 days ago
JSON representation
Clock-accurate timeout for Node.js and browser
- Host: GitHub
- URL: https://github.com/pakastin/clocktick
- Owner: pakastin
- Created: 2014-08-27T00:15:44.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2015-07-09T11:33:25.000Z (over 9 years ago)
- Last Synced: 2024-10-19T05:10:29.530Z (26 days ago)
- Language: JavaScript
- Homepage: http://pakastin.github.io/clocktick
- Size: 238 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# clocktick
Clock-accurate timeout for Node.js and browser.
Basically it is identical to setTimeout, but it triggers callback function precisely on the next second.## example
See an example [here](http://pakastin.github.io/clocktick)## accuracy
Accuracy should be around 1–2ms.## installation
npm install clocktick
## usage
Usage is similar to setTimeout, but without delay parameter:var tick = require('clocktick')
tick(callback) // Ticks every secondYou can use the delay parameter, but it is in seconds:
tick(callback, 2) // Ticks on 2nd second (00, 02, 04, 06, 08, 10,...)
You can also offset seconds:tick(callback, 3) // Ticks on 3rd second (03, 06, 9, 12, 15, 18, ...)
tick(callback, 3, 1) // Ticks on 3rd+1 second (04, 07, 10, 13, 16, 19, ...)
tick(callback, 3, 2) // Ticks on 3rd+2 second (05, 08, 11, 14, 17, 20, ...)## repeat
You can repeat the tick by just calling it again:
tick(callback)
function callback () {
console.log('tick')
tick(callback)
}## cancel
You can cancel the tick by using clearTimeout:
var timeout = tick(callback)
clearTimeout(timeout)
## testing
Clone to desktop and then run following commands at clocktick folder:npm install
npm test## building
npm install
npm run build