Skip to content

Instantly share code, notes, and snippets.

@jonathanrz
Created November 6, 2017 23:12
Show Gist options
  • Select an option

  • Save jonathanrz/1c5e33082dda4b05fcc5343ef7d47dd4 to your computer and use it in GitHub Desktop.

Select an option

Save jonathanrz/1c5e33082dda4b05fcc5343ef7d47dd4 to your computer and use it in GitHub Desktop.
import io.reactivex.Observable;
import io.reactivex.subjects.BehaviorSubject;
public class Q47000608 {
public static void main(String[] args) {
BehaviorSubject<Integer> bs = BehaviorSubject.createDefault(1);
Observable<Integer> o = bs.replay(1).autoConnect().distinctUntilChanged();
o.subscribe(i -> System.out.println("s1 accept " + i));
bs.onNext(2);
o.subscribe(i -> System.out.println("s2 accept " + i));
o.subscribe(i -> System.out.println("s3 accept " + i));
bs.onNext(3);
o.subscribe(i -> System.out.println("s4 accept " + i));
bs.onNext(4);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment