Skip to content
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

OperatorAny needs to handle backpressure #1473

Merged
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 @@ -39,6 +39,7 @@ public Subscriber<? super T> call(final Subscriber<? super Boolean> child) {
return new Subscriber<T>(child) {
boolean hasElements;
boolean done;

@Override
public void onNext(T t) {
hasElements = true;
Expand All @@ -48,6 +49,9 @@ public void onNext(T t) {
child.onNext(!returnOnEmpty);
child.onCompleted();
unsubscribe();
} else {
// if we drop values we must replace them upstream as downstream won't receive and request more
request(1);
}
}

Expand All @@ -68,7 +72,7 @@ public void onCompleted() {
child.onCompleted();
}
}

};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package rx.internal.operators;

import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
Expand All @@ -27,6 +28,8 @@
import rx.functions.Func1;
import rx.functions.Functions;

import java.util.Arrays;

public class OperatorAnyTest {

@Test
Expand Down Expand Up @@ -197,4 +200,16 @@ public Boolean call(Integer t1) {
verify(observer, never()).onError(org.mockito.Matchers.any(Throwable.class));
verify(observer, times(1)).onCompleted();
}

@Test
public void testWithFollowingFirst() {
Observable<Integer> o = Observable.from(Arrays.asList(1, 3, 5, 6));
Observable<Boolean> anyEven = o.exists(new Func1<Integer, Boolean>() {
@Override
public Boolean call(Integer i) {
return i % 2 == 0;
}
});
assertTrue(anyEven.toBlocking().first());
}
}