Created
March 29, 2016 17:35
-
-
Save tcw165/0e4e3dc0e4e001c7aa2b0297d752ff4e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_log("Before Observable"); | |
// Create a "cold" observable. | |
Observable<Boolean> ob = Observable | |
// The "just" convert a boolean into an Observable. | |
.just(true) | |
// Transform the items emitted by an Observable by applying a function to each item. | |
.map(new Func1<Boolean, Boolean>() { | |
@Override | |
public Boolean call(Boolean aBoolean) { | |
_log("Within Observable"); | |
_doSomeLongOperation_thatBlocksCurrentThread(); | |
return aBoolean; | |
} | |
}) | |
// Run Observable asynchronously. | |
.subscribeOn(Schedulers.io()) | |
// Emit the items to subscribers on main thread. | |
.observeOn(AndroidSchedulers.mainThread()); | |
// Observe and get the subscription (like a voucher). | |
Subscription subscription = ob | |
.subscribe(new Action1<Boolean>() { | |
@Override | |
public void call(Boolean bool) { | |
_log(String.format("Call with return value \"%b\"", bool)); | |
} | |
}); | |
_log("Right after Observable"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment