Andrea Giuliano
09/03/2020, 2:38 PM.asContextElement()
extension function to make them coroutine-ready. All works well but i find my code having something like this
launch(object1.asContextElement() + object2.asContextElement()) {}
I was thinking to encapsulate those element into a container such that I can do something like this
launch(myContext) {}
where mycontext
contains the elements from object1 and object2.
I was thinking to do this by implementing the CoroutineContext
interface but I then I need to implement all its functions, while what I really want is just the default +
behavior. Is there any nice way to achieve this?elizarov
09/03/2020, 2:40 PMval myContext = object1.asContextElement() + object2.asContextElement()
Andrea Giuliano
09/03/2020, 2:41 PMelizarov
09/03/2020, 2:41 PMAndrea Giuliano
09/03/2020, 2:41 PMelizarov
09/03/2020, 2:42 PMobject MyContext: CoroutineContext by (object1.asContextElement() + object2.asContextElement())
Andrea Giuliano
09/03/2020, 2:42 PMobject MyContext: CoroutineContext by (object1.asContextElement() + object2.asContextElement())this is amazing, will try this one. let me see if I can make it working with DI