1.0.0 • Published 7 years ago

picotimer v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

About

A tiny timer that emits a "tick" event at given interval(defaults to 1 second) showing the actual time passed. Emits a "finished" event once done.

Install

$ npm install picotimer
# OR
$ yarn add picotimer

Usage

const Timer = require('picotimer')

const timer = new Timer(10000) // 10 Second timer
const otherTimer = new Timer(5000, { interval: 500 }) // 5 Second timer that will emit "tick" event every half second

timer.on('tick', remaining => {
  console.log(remaining)
  console.log(timer.hasFinished, timer.hasStarted)

  if (remaining < 3000) {
    timer.stop() // Stop it prior to finishing
    otherTimer.start()
  }
})

otherTimer.on('tick', console.log)
otherTimer.on('finished', () => {
  console.log(`That's all folks!`)
})

timer.start()

// 9000
// false true
// 8002.929022
// false true
// 7010.797439
// false true
// 6026.31589
// false true
// 5052.967289
// false true
// 4095.9625599999995
// false true
// 3158.4987889999984
// false true
// 2242.239962999997
// false true
// 4500
// 4004.104806
// 3516.2985419999995
// 3041.2491829999994
// 2582.125558999999
// 2144.1727109999993
// 1731.8530529999996
// 1347.7554280000008
// 993.3701170000043
// 671.8532830000131
// 386.8910150000363
// 142.10573800009797

Contributing

Contributions are welcome!

  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 :D

Or open up a issue.

License

Licensed under the MIT License.