Closed
Description
This code:
import rx.Observable;
import rx.Subscription;
import rx.subjects.PublishSubject;
final class Unsubscribing {
private static Subscription mFirst;
private static Subscription mSecond;
public static void main(final String[] args) {
final PublishSubject<Integer> publisher = PublishSubject.create();
mFirst = publisher.subscribe(i -> {
mSecond.unsubscribe();
log("first: " + i);
} );
mSecond = publisher.subscribe(i -> {
log("second: " + i);
} );
publisher.onNext(1);
publisher.onNext(2);
}
private static void log(final String msg) {
System.out.println(msg);
}
}
Unsubscribes second subscription in the first callback. At the time second callback called it is not subscribed (unsubscribe call completed for it).
It's expected that second callback will not be called, but it is.
Output of that program is
first: 1
second: 1
first: 2