1.2.0 • Published 4 years ago

timer-precise v1.2.0

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

timer

精确计时工具

计时是业务中常见的需求,由于 javaScript 单线程特性,定时器的执行时机是不能保证的。我们采用对照本地时间的方法,实现了精确计时。

特性

  • typescript 支持
  • 精确计时,没有延迟
  • 毫秒级计时
  • 开始,暂停,继续,复位
  • 倒计时和正计时
  • 无终点计时

使用

  • 安装
npm install timer-precise
  • 使用
import Timer form 'timer-precise';

const timer = new Timer({
  duration: 60000,
  interval: 500,
  callback(time) {
    console.log(time);
  }
});

timer.start()
  • 参数 Object

    key类型说明默认值必填
    durationnumber计时时长,如果为 0,则计时不会停止,直到手动停止0 (毫秒)
    intervalnumber计时频率1000(毫秒)
    callbackfunction计时回调,每 interval 毫秒调用一次()=>{}
  • callback 参数 Object

    key类型说明
    beforeobject已经过去的时间,例如 {d: 0, h: 2, m: 0, s: 1, ms: 300}
    afterobject剩余时间,例如{d: 1, h: 0, m: 2, s: 1, ms: 0}
    msBeforenumber已经过去的时间(毫秒数)
    msAfternumber剩余时间(毫秒数)
  • 实例方法

    方法说明
    start开始(继续)
    stop暂停
    reset复位(销毁),应用卸载时应调用此方法
1.2.0

4 years ago

1.1.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago