eygraber
10/20/2017, 6:41 PMRunnable
that makes the network call and writes the response.
Using Rx it would look something like:
quoteService
.getQuote()
.flatMap(response::write)
.subscribeOn(<http://Schedulers.io|Schedulers.io>())
.subscribeBy(
onSuccess = {},
onError = {}
)
I'm not great with coroutines, but I assume it would look something like:
async {
try {
val quote = quoteService.getQuote().await()
response.write(quote)
catch(_: Exception) {}
}
Is it just about the style of programming, or do coroutines offer something major over the other approaches? I see a few places that mention coroutines are non-blocking, but they don't seem to be, at least not in the same way that non-blocking io works.
Can anyone help clarify this?voddan
10/20/2017, 7:39 PMuli
10/20/2017, 8:16 PMeygraber
10/20/2017, 9:53 PMvoddan
10/21/2017, 4:45 AMBetter performance, more throughput, etc,Coroutines cover more use cases than RX, for example
yield
. I guess you could also get more performance if running coroutines in a single thread.
Anyways what you call style of coding
, and what I call different abstraction
, is the main benefit of Coroutines, and all else are just bonuses.uli
10/21/2017, 7:30 AMeygraber
10/22/2017, 5:09 AMrocketraman
10/22/2017, 5:42 AM"When the only tool you know is a hammer, everything looks like a nail."I think you would benefit from some time learning some additional tools beyond your rx hammer (and coroutines is a powerful one with multiple sub-tools... I'd at least add actors and good old shared state to the mix as well), so you can recognize which problems require which solutions.