Skip to content

Add 'request(Long.MAX_VALUE)' in 'onStart' to fix the backpressure issue of debounce #2851

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ public Subscriber<? super T> call(final Subscriber<? super T> child) {
return new Subscriber<T>(child) {
final DebounceState<T> state = new DebounceState<T>();
final Subscriber<?> self = this;

@Override
public void onStart() {
request(Long.MAX_VALUE);
}

@Override
public void onNext(final T t) {

Expand Down
18 changes: 18 additions & 0 deletions src/test/java/rx/internal/operators/OperatorDebounceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import org.junit.Before;
Expand All @@ -36,6 +37,7 @@
import rx.exceptions.TestException;
import rx.functions.Action0;
import rx.functions.Func1;
import rx.observers.TestSubscriber;
import rx.schedulers.TestScheduler;
import rx.subjects.PublishSubject;

Expand Down Expand Up @@ -287,4 +289,20 @@ public Observable<Integer> call(Integer t1) {
verify(o).onCompleted();
verify(o, never()).onError(any(Throwable.class));
}

@Test
public void debounceWithTimeBackpressure() throws InterruptedException {
TestScheduler scheduler = new TestScheduler();
TestSubscriber<Integer> subscriber = new TestSubscriber<Integer>();
Observable.merge(
Observable.just(1),
Observable.just(2).delay(10, TimeUnit.MILLISECONDS, scheduler)
).debounce(20, TimeUnit.MILLISECONDS, scheduler).take(1).subscribe(subscriber);

scheduler.advanceTimeBy(30, TimeUnit.MILLISECONDS);

subscriber.assertReceivedOnNext(Arrays.asList(2));
subscriber.assertTerminalEvent();
subscriber.assertNoErrors();
}
}