pmrs
pmrs

Reputation: 73

RxJava debounce

I'm trying to debounce a 100ms producer within a 1000ms window. I would expect to see the subscription being updated every 1 second with the last value emitted that period, however I am not getting anything. What am I missing here?

public static void main(String[] args) throws InterruptedException {
    Observable
      .interval(100, TimeUnit.MILLISECONDS)
      .debounce(1000, TimeUnit.MILLISECONDS)
      .subscribe(
          update -> System.out.println(new Date().toString() + " " + update),
          error -> System.out.println("ERROR")
      );
    Thread.sleep(20000);
  }

Upvotes: 2

Views: 597

Answers (1)

pmrs
pmrs

Reputation: 73

Found it. I was trying to find in RXJava an operator equivalent to RxJS's debounceTime(), which happen to be sample() or throttleLast().

Upvotes: 1

Related Questions