Can a `suspend` function somehow find out in which...
# coroutines
a
Can a
suspend
function somehow find out in which dispatcher/executor is it running now?
g
Yes, just find CoroutineDispatcher in coroutineContext
Coroutine context is like a map
And each context has key
Not sure what you mean about "executor"
a
executor is something I need to find I need to run my 3rd-party library callback in the same thread coroutine is running, and callback wants an executor
g
What is executor?
g
So you have a CoroutineDispatcher backed by custom executor? Just find Coroutine Dispatcher in coroutine context:
Copy code
val dispatcher = coroutineContext[CoroutineDispatcher]
Than you can cast to ExecutorCoroutineDispatcher and get executor from property