Does running a series of coroutine operations in a...
# coroutines
c
Does running a series of coroutine operations in a blocking context force all inner functionality to run synchronously? say you had something like
Copy code
runBlocking {

  val (foo,bar) = doAsync({ foo() },{ bar() })
  
  val (baz,bax) = doAsync({ baz(foo) },{ bax(bar) })

  return listOf(foo,bar,baz,bax)

}
Assuming doAsync runs the inner lambdas concurrently, would runBlocking the outer scope force these to run synchronously ?
w
No, runBlocking doesn’t mean thing inside are blocking one another, it’s just a coroutine builder that only returns after the coroutines inside have finished
But you still need to have enough threads available if things run in parallel, like
withContext(<http://Dispatchers.IO|Dispatchers.IO>)
for example (unless the async stuff can run in concurrently on one thread)
v
async stuff can run in concurrently on one thread => foo, bar, baz, and bax are suspending, and have suspension points in them ?
t
Yes. I use async quite a bit, but for my use-case I only run 1 thread. So I effectively have a bunch of "green threads" that are doing cooperative multitasking. And yes, every time they hit something that suspends, they effective give up control and let something else run.