Joan Colmenero
10/27/2019, 8:16 PMclass ContentPresenter(
private val useCase: ContentUseCase,
private val contextPool: CoroutineContextProvider = CoroutineContextProvider()
) {
....
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
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?tseisel
10/28/2019, 9:40 PMCoroutineContextProvider 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.