https://kotlinlang.org logo
#coroutines
Title
# coroutines
a

aaverin

09/19/2018, 5:14 AM
Can a
suspend
function somehow find out in which dispatcher/executor is it running now?
g

gildor

09/19/2018, 8:17 AM
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

aaverin

09/19/2018, 2:11 PM
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

gildor

09/19/2018, 3:43 PM
What is executor?
g

gildor

09/20/2018, 1:22 AM
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
3 Views