Is it ever ok to use runBlocking in regular code? ...
# announcements
k
Is it ever ok to use runBlocking in regular code? Somehow that seems wrong
e
on a thread that doesn't belong to a Dispatcher, sure
k
What if that code is run on the Main thread?
(I'm asking because we have a library that does this. It just seems dangerous)
e
you should know the answer of whether the main thread is ok to block or not regardless of
runBlocking
e.g. UI main thread blocking bad, console main thread blocking (generally) ok
2
c
One example where it's ok I want to use java.util.stream:
Copy code
myList.stream()
  .parallel()
  .map { runBlocking { ... } }
e
why not
myList.map { async { ... } }.awaitAll()
which handles cancellation better
c
Yep, your version is better. Thanks. It doesn't feel natural for complicated pipelines though, but I guess that's fine
g
I'm curious what is your use case for parallel stream, because it may require a but different code, depending on cass