Say `suspend fun getX()` needs to be able to be ru...
# coroutines
d
Say
suspend fun getX()
needs to be able to be run either in main thread context using
CommonPool
, or in an existing
coroutineContext
or in an already existing worker thread in a blocking fashion, depending on from where it's called, what's the recommended way to do each, and when would I have to
yield
?
e
The recommend practice is to write
suspend fun getX()
as you would normally do and delegate decision on what context to run it in to its caller.
d
The
getX()
in my case is the
channel.send(parsedApiActions)
, that is supposed to dispatch actions to the channel that will fan out to handlers and fan in again for results, the results need to be recieved on the current thread but the processing is done in a thread pool...
e
The context shall be specified around the context-sensitive code. If your handlers need to be run a specific thread, they have to be launched in the context of the specific thread. The code that invoked
send
should not be even remotely concerned about that.