RxJS timeInterval

2020-10-13 18:07 更新

发出一个包含当前值和时间的对象 在发出当前值和上一个值之间传递 使用提供 schedulernow()方法检索 每次发射的当前时间,然后计算差异。 的 scheduler 默认为 async,因此默认情况下, interval将位于 毫秒。

timeInterval<T>(scheduler: SchedulerLike = async): OperatorFunction<T, TimeInterval<T>>

参量

调度器 可选的。 默认值为 async。 调度程序用于获取当前时间。

returns

OperatorFunction<T, TimeInterval<T>>:可观察到的有关值和间隔的信息

描述

将发出项目的 Observable 转换为 发出两次排放之间所经过时间的指示。

例子

发出当前值与最后一个值之间的间隔

  1. const seconds = interval(1000);
  2. seconds.pipe(timeInterval())
  3. .subscribe(
  4. value => console.log(value),
  5. err => console.log(err),
  6. );
  7. seconds.pipe(timeout(900))
  8. .subscribe(
  9. value => console.log(value),
  10. err => console.log(err),
  11. );
  12. // NOTE: The values will never be this precise,
  13. // intervals created with `interval` or `setInterval`
  14. // are non-deterministic.
  15. // {value: 0, interval: 1000}
  16. // {value: 1, interval: 1000}
  17. // {value: 2, interval: 1000}
以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号