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

dave08

12/20/2018, 1:15 PM
Is there a way to retrieve the android Handler from coroutineContext?
g

gildor

12/20/2018, 1:50 PM
You can get dispatcher but there is no public method to get handler from dispatcher
coroutineContext[Dispatcher]
d

dave08

12/20/2018, 2:13 PM
Oh... I'm trying to adapt a library's callbacks to coroutines, and I need to pass it a handler in
suspendCoroutine { }
so that it can run on it... 😕
g

gildor

12/20/2018, 3:53 PM
I’m not sure about your case. Can you give little bit more context
Just create a handler or pass it to await function, why do you need Handler from coroutineContext? Because coroutineContext may have no any dispatcher or no HandlerDispatcher
d

dave08

12/20/2018, 6:00 PM
I need to run a library on my android service's Handler, but it would be a plus if I could have it run on the caller CoroutineScope's dispatcher handler?
g

gildor

12/20/2018, 11:26 PM
But what if caller doesn't use dispatcher with handler
Why not just let user of API pass handler if it's important
6 Views