Skip to content

1.x: observeOn + immediate scheduler to be a request rebatcher #3964

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

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 1 addition & 4 deletions src/main/java/rx/internal/operators/OperatorObserveOn.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ public OperatorObserveOn(Scheduler scheduler, boolean delayError, int bufferSize

@Override
public Subscriber<? super T> call(Subscriber<? super T> child) {
if (scheduler instanceof ImmediateScheduler) {
// avoid overhead, execute directly
return child;
} else if (scheduler instanceof TrampolineScheduler) {
if (scheduler instanceof TrampolineScheduler) {
// avoid overhead, execute directly
return child;
} else {
Expand Down
25 changes: 24 additions & 1 deletion src/test/java/rx/internal/operators/OperatorObserveOnTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;

import org.junit.Test;
import org.junit.*;
import org.mockito.InOrder;

import rx.*;
Expand Down Expand Up @@ -933,4 +933,27 @@ public void bufferSizesWork() {
ts.assertNoErrors();
}
}

@Test
public void synchronousRebatching() {
final List<Long> requests = new ArrayList<Long>();

TestSubscriber<Integer> ts = new TestSubscriber<Integer>();

Observable.range(1, 50)
.doOnRequest(new Action1<Long>() {
@Override
public void call(Long r) {
requests.add(r);
}
})
.observeOn(Schedulers.immediate(), 20)
.subscribe(ts);

ts.assertValueCount(50);
ts.assertNoErrors();
ts.assertCompleted();

Assert.assertEquals(Arrays.asList(20L, 15L, 15L, 15L), requests);
}
}