BąQ
BąQ

Reputation: 306

RxJS DebounceTime doesn't work with interval

I have one question regarding debounceTime and interval from rxjs.

Why debounceTime is not working with combination with interval?

E.g.

import {interval} from "rxjs";
import {debounceTime} from "rxjs/operators";

const int$ = interval(1000);

console.log("Start", Date.now());
int$.pipe(
  debounceTime(2000)
).subscribe(val => console.log("With Debounce", Date.now()))

int$.subscribe(val => console.log("Without Debounce", Date.now()))

In above case "With Debounce" will be never put into console.

Upvotes: 2

Views: 183

Answers (1)

BizzyBob
BizzyBob

Reputation: 14740

debounceTime - Emits a notification from the source Observable only after a particular time span has passed without another source emission.

Since your interval time is less than your debounceTime, no emissions will occur, because the time span is never exceeded without receiving another emission.

If you change debounceTime to 500, you will get emissions. however the effect would be the same as omitting debounceTime altogether.

I actually can’t think of a case where using debounceTime with interval would be useful.

What are you trying to achieve?

Upvotes: 2

Related Questions