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 PMvoddan
10/20/2017, 7:39 PMuli
10/20/2017, 8:20 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.