Skip to content

Instantly share code, notes, and snippets.

@SergejIsbrecht
Created October 27, 2016 20:22
Show Gist options
  • Save SergejIsbrecht/2d6a20283d7c3ea304af0cf54f0650b4 to your computer and use it in GitHub Desktop.
Save SergejIsbrecht/2d6a20283d7c3ea304af0cf54f0650b4 to your computer and use it in GitHub Desktop.
ConnectableObservable<Boolean> booleanObservable = Observable
.fromCallable(() -> {
Thread.sleep(1_000);
return true;
}).startWith(false)
.subscribeOn(Schedulers.io())
.replay(2);
Disposable sub1 = booleanObservable
.doOnSubscribe(disposable -> {
printCurrentThread("SUBSCRIBED1");
})
.observeOn(AndroidSchedulers.mainThread())
.subscribe(aBoolean -> {
printCurrentThread("1SubCallback: " + String.format("%1$s", aBoolean));
});
booleanObservable.connect();
try {
Thread.sleep(2_000);
} catch (InterruptedException e) {
e.printStackTrace();
}
booleanObservable.doOnSubscribe(disposable -> {
printCurrentThread("SUBSCRIBED2");
}).observeOn(AndroidSchedulers.mainThread())
.subscribe(aBoolean -> {
if (!aBoolean) {
// show loading here:::::
printCurrentThread("2SubCallback_showLoading: " + String.format("%1$s", aBoolean));
} else {
printCurrentThread("2SubCallback_doStuff: " + String.format("%1$s", aBoolean));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment