Last active
April 20, 2019 11:39
-
-
Save tcw165/b12b82c8df5ec957a7724fead13005e4 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
fun brewCoffee(): Single<Coffee> { | |
return Single | |
.fromCallable { | |
// Simulate the machine takes random time up to 5s to brew a coffee. | |
Thread.sleep(5 * 60 * 1000 * Math.random()) | |
// The machine have chance to crash with no reason. | |
if (0.5f < Math.random()) throw RuntimeException() | |
return@Callable Coffee() | |
} | |
.subscribeOn(Schedulers.io()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment