Ivan Talalaev
Ivan Talalaev

Reputation: 6494

rxjs debounce and interval

There are lots of information and questions about RXJS debounce method. But I cannot understand why this most simple example doesn't work:

Rx.Observable.interval(1000)
  .debounce(() => Rx.Observable.interval(2500))
  .subscribe(result  => console.log(result, '!'));

Interval emits incremental number every 1 second (assume ---- is one second)

---1---2---3---4---5
---------d---------d

In this case I expected to see 2 and 5 numbers, but it shows nothing.

What I'm doing wrong?

Upvotes: 1

Views: 752

Answers (1)

Mark van Straten
Mark van Straten

Reputation: 9425

debounce waits until no emissions are done for x time and then emits the last value

-a-b-b-c----a---
----------c----a

If you want to have only one value for every x time units then you can look at buffer or window operators

Upvotes: 1

Related Questions