https://kotlinlang.org logo
#coroutines
Title
# coroutines
d

davidasync

03/16/2019, 12:46 PM
Hello, http clients that utilize
java NIO
already have asynchronous nature for example Jetty Http Client, asynchttpclient, apache async http client, and etc is it necessary to wrap it with coroutines to do parallel http call ?
d

Dominaezzz

03/16/2019, 12:52 PM
This is not necessary but wrapping it with coroutine apis gives you other nice features that coroutines give you, like structured concurrency, etc.
d

davidasync

03/16/2019, 1:01 PM
is it will improve / reduce the performance of http client itself ?
d

Dominaezzz

03/16/2019, 1:08 PM
Although those clients use non-blocking apis, the methods are still synchronous and suspend the running coroutine. You will need multiple coroutines to run multiple requests in parallel.
You don't necessarily need to spawn those coroutines off the main thread though.
d

davidasync

03/16/2019, 2:14 PM
I see, thanks for the insight~
s

sitepodmatt

03/17/2019, 3:30 AM
if they have a callback you can convert them to suspendable functions using suspendCancellableCoroutine { cont -> blahh // oncallback { cont.resume and so on
d

dekans

03/17/2019, 9:35 AM
Or Cahnnels, or CompletableDeferred. It won't improve performance. But it will make your code easier to read.
7 Views