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

OperatorTakeLast add check for isUnsubscribed to fast path #2244

Merged
merged 1 commit into from
Jan 19, 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 @@ -70,6 +70,8 @@ void emit(long previousRequested) {
if (previousRequested == 0) {
try {
for (Object value : deque) {
if (subscriber.isUnsubscribed())
return;
notification.accept(subscriber, value);
}
} catch (Throwable e) {
Expand Down
29 changes: 29 additions & 0 deletions src/test/java/rx/internal/operators/OperatorTakeLastTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static org.mockito.Mockito.verify;

import java.util.Arrays;
import java.util.concurrent.atomic.AtomicInteger;

import org.junit.Test;
import org.mockito.InOrder;
Expand Down Expand Up @@ -264,4 +265,32 @@ public void onNext(Integer integer) {
}
});
}

@Test
public void testUnsubscribeTakesEffectEarlyOnFastPath() {
final AtomicInteger count = new AtomicInteger();
Observable.range(0, 100000).takeLast(100000).subscribe(new Subscriber<Integer>() {

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

@Override
public void onCompleted() {

}

@Override
public void onError(Throwable e) {
}

@Override
public void onNext(Integer integer) {
count.incrementAndGet();
unsubscribe();
}
});
assertEquals(1,count.get());
}
}