Anyone of you can give me other approach of this: ...
# coroutines
j
Anyone of you can give me other approach of this:
Copy code
class ContentPresenter(
        private val useCase: ContentUseCase,
        private val contextPool: CoroutineContextProvider = CoroutineContextProvider()
) {
....
Copy code
open class CoroutineContextProvider {
    open val Main: CoroutineContext by lazy { UI }
    open val IO: CoroutineContext by lazy { CommonPool }
}
Then inside of each presenter I'm doing
Copy code
launch(contextPool.Main) {
            val content = withContext(<http://contextPool.IO|contextPool.IO>) {
                repository.requestContent()
            }
            view.displayContent(content)
        }
On every presenter I'm passing the
CoroutineContextProvider
in order to test it with
unit testing
then for testing I have the
TestCouroutineContextProvider
which I use
Unconfined
, the thing is, do you guys are you using something like
AbstractPresenter
where you have there the
Job
and then you only from the presenter call it? I'd like to abstract it a little bit, and then could use my presenter without passing the
CoroutineContextProvider
via parameter, and then use it also in
unit testing
. Could you help me out with this?
t
Inheriting from an abstract base presenter won't remove the need to inject
CoroutineContextProvider
via the constructor. if you're using Dagger 2 you probably won't mind having this extra constructor parameter anyway, as Dagger 2 automatically generates the correct factory.