Giter Site home page Giter Site logo

clock-tickr's Introduction

ClockTickr โฐ

A very simple ticker that emits tick events at a clock-synchronised, self-adjusting interval.

JavaScript Style Guide

Features

  • It ticks at the specified interval.
  • It keeps itself synchronised with the system clock.
  • .. more ticks.

Installation

npm install --save clock-tickr

Usage:

Create a ClockTickr instance, with an optional tick interval in ms (default is 1000) and start it. See below.

const ClockTickr = require('clock-tickr')

let tickr = new ClockTickr({ interval: 250 })

tickr.on('tick', (tick) => {
  console.log(tick)
  if (Math.abs(tick.drift) > 20) {
    console.log('Did you travel in time?')
  }
})

tickr.start()

results in (when you change the system time while running)

...
{ actual: 1539887917504, expected: 1539887917500, drift: 4 }
{ actual: 1539887917753, expected: 1539887917750, drift: 3 }
{ actual: 1539886920168, expected: 1539887918000, drift: -997832 }
Did you travel in time?
{ actual: 1539886920501, expected: 1539886920500, drift: 1 }
{ actual: 1539886920751, expected: 1539886920750, drift: 1 }
...

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request

Credits

License

MIT

clock-tickr's People

Contributors

coussej avatar

Watchers

 avatar  avatar

Forkers

proarsing

clock-tickr's Issues

Time drift

Hello,

We are currently debugging an issue where we seem to be having time drift.
The first point that is ticked is at the right time, but the longer the ticker goes for, the more it seems to trail behind on the actual time.
Any insight as to what might cause this issue would be greatly appreciated.

Kind regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.