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
napperley
10/21/2017, 1:59 AM
Would DB queries be another good example?
e
elizarov
10/21/2017, 9:26 AM
DB queries as a good example of what?
n
napperley
10/22/2017, 4:21 AM
An example of a task that is network bound that would benefit from coroutines.
e
elizarov
10/22/2017, 7:49 PM
If you have an async DB driver, then yes.
n
napperley
10/23/2017, 1:24 AM
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
elizarov
10/23/2017, 9:33 AM
JDBC isn’t async yet, but JDBC 2.0 (work in progress now) will be.