louiscad
08/05/2018, 10:42 PMHandler?.
Since coroutines already have the concept of dispatcher, there's a kind of concept duplication (although Handler is single threaded, unlike `CoroutineDispatcher`s).
I'd like to avoid this leaking into the API of my library as method parameters, so I'm thinking about putting the Handler into the CoroutineContext so it can be retrieved by the library. Do you think it's a good usage of CoroutineContext ThreadLocal-like abilities?gildor
08/06/2018, 1:57 AMVsevolod Tolstopyatov [JB]
08/06/2018, 12:52 PMHandlerContext with public Handler property. Feel free to post your solution when it’s ready, maybe we can improve something in coroutines-androidlouiscad
08/07/2018, 7:41 AMhandler property on HandlerContext, I'd probably have used it in the past to avoid having to pass an extra Handler, but I think I'd not do this today, because it can stop working if you add a withContext that switches thread.
I'll probably resume my work by the next weekend, I'll give an update on how it went and my struggles if anylouiscad
08/07/2018, 11:34 AMval handler = coroutineContext[HandlerElement]?.handler
?: illegal("Required Handler was not found in coroutineContext")
provided that illegal returns Nothing.louiscad
08/07/2018, 11:38 AMHandlerContext, especially since I may use it while running the coroutine in another CoroutineDispatcher like CommonPool, UI or the experimental dispatcher (and not the HandlerThread) which would replace the HandlerContext.