如何在rxjs中每5次调用后进行延迟?

时间:2019-10-19 08:25:11

标签: rxjs

我有无尽的事件流,我需要将事件限制为5个,其余的都暂停3秒

因此,每5个通话后需要延迟

2 个答案:

答案 0 :(得分:2)

const obj = { a: 1, b: 2 }
// You can access its item values by key:
array.a => 1
array['b'] => 2

您可以在我制作的this stackblitz中看到。

答案 1 :(得分:1)

const stream = range(0, 100) // create dataset
  .pipe(
    bufferCount(5), // slice data into chunks
    concatMap( // get this chunk 
      (msg) => of(msg).pipe(
        delay(3000) // and emit every three seconds
      ))
  )
stream.subscribe(item => console.log(item));