简体   繁体   中英

RxJS: Take every x seconds

with RXJs I am trying to achieve something like this:

  1. clickStream.bufferWithTime(500).subscribe(f)
  2. clickStream.throttle(500).subscribe(f)

Version 1 calls f every 500ms no matter if there was a clickEvent or not. Version 2 calls f only if clickStream did send a clickEvent and then stopped for at least 500ms.

I would like to to call f every 500ms as long as clickStream is emitting events. As soon as it does stop to emit, f should called be one last time. If clickStream restarts to emit the same should happen again.

clickStream.bufferWithTime(500).filter(arr => arr.length > 0).subscribe(f)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM