Skip to content

ZipIterable unsubscription fix #1254

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 1 commit into from
May 27, 2014
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 @@ -43,10 +43,14 @@ public Subscriber<? super T1> call(final Subscriber<? super R> subscriber) {
} catch (Throwable e) {
subscriber.onError(e);
}
return new Subscriber<T1>() {

return new Subscriber<T1>(subscriber) {
boolean once;
@Override
public void onCompleted() {
if (once) {
return;
}
once = true;
subscriber.onCompleted();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import java.util.Arrays;
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;
Expand All @@ -31,6 +33,8 @@
import rx.Observable;
import rx.Observer;
import rx.exceptions.TestException;
import rx.functions.Action1;
import rx.functions.Func1;
import rx.functions.Func2;
import rx.functions.Func3;
import rx.subjects.PublishSubject;
Expand Down Expand Up @@ -346,4 +350,32 @@ public void remove() {
verify(o, never()).onCompleted();

}

Action1<String> printer = new Action1<String>() {
@Override
public void call(String t1) {
System.out.println(t1);
}
};

static final class SquareStr implements Func1<Integer, String> {
final AtomicInteger counter = new AtomicInteger();
@Override
public String call(Integer t1) {
counter.incrementAndGet();
System.out.println("Omg I'm calculating so hard: " + t1 + "*" + t1 + "=" + (t1*t1));
return " " + (t1*t1);
}
}

@Test public void testTake2() {
Observable<Integer> o = Observable.from(1, 2, 3, 4, 5);
Iterable<String> it = Arrays.asList("a", "b", "c", "d", "e");

SquareStr squareStr = new SquareStr();

o.map(squareStr).zip(it, concat2Strings).take(2).subscribe(printer);

assertEquals(2, squareStr.counter.get());
}
}