Is there any way to retrieve the dispatcher from a...
# coroutines
e
Is there any way to retrieve the dispatcher from a coroutine context?
a
yes, but there generally isn't a lot of reason to, why?
e
I'm wrapping a 3rd party API that expects an executor in a
suspendCancellableCoroutine
. I want to be able to get the dispatcher from the continuation's context and turn that into an executor
a
thought that might be it. 🙂 You don't need to. Use a directExecutor and just resume the continuation with the right result, it'll dispatch to the right CoroutineDispatcher as part of resuming the continuation
e
Is that from Guava?
a
Yes but you can make your own trivially:
Copy code
object DirectExecutor : Executor {
  override fun execute(r: Runnable) {
    r.run()
  }
}
e
Interesting. Thanks!