Alessandro Diaferia12/11/2019, 3:10 PM
that works off an IO dispatcher (
) and now I’d need to use a class from an external library that is not thread-safe and requires a heavy initialization phase (in the order of a few seconds) per thread. How should I approach this problem? Would I simply initialize one instance and add it to the current
? How would its access be regulated to make sure there is no concurrent multi-thread access from the various coroutines spread across multiple threads (I assume
spans across multiple threads). Any help appreciated.
-based initialization but I’d be interested in a more idiomatic coroutine-ish approach
bezrukov12/11/2019, 3:13 PM
Alessandro Diaferia12/11/2019, 3:15 PM
Kevin Gorham12/11/2019, 3:22 PM
, perhaps by using a
for communication. Meaning, you would send messages into the channel and then consume them as a flow, wherever needed.
Alessandro Diaferia12/11/2019, 3:34 PM
applies in this case. My main constraint is that I have to be sure a different instance of this library has been initialized per thread. Once that’s done, I should be able to use it safely from any coroutine. So basically, every time my coroutine starts or resumes I have to make sure the library instance being used has been initialized.
Kevin Gorham12/11/2019, 3:41 PM