Skip to content

Instantly share code, notes, and snippets.

@tcw165
Last active April 20, 2019 11:39
Show Gist options
  • Save tcw165/b12b82c8df5ec957a7724fead13005e4 to your computer and use it in GitHub Desktop.
Save tcw165/b12b82c8df5ec957a7724fead13005e4 to your computer and use it in GitHub Desktop.
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