Coroutines are good if your work that you have to ...
# coroutines
e
Coroutines are good if your work that you have to do on each element is asynchronous (needs to wait for something, like network call). If it is all just CPU-bound, you’d be better off using Java parallel streams — they are specifically optimized for parallelization of CPU-bound computations.
👍 6
n
Would DB queries be another good example?
e
DB queries as a good example of what?
n
An example of a task that is network bound that would benefit from coroutines.
e
If you have an async DB driver, then yes.
n
Unfortunately JDBC isn't async so other Java/Kotlin libs/frameworks/toolkits that utilise async programming (eg Vert.x) end up having to create their own workarounds, which creates a big mess. 🙁
e
JDBC isn’t async yet, but JDBC 2.0 (work in progress now) will be.