Hi guys I have a very basic question from coroutin...
# android-architecture
s
Hi guys I have a very basic question from coroutine about the design decision. Here I am posting 2 options and I would like to listen which approach you guys think is better and why
Copy code
//////      Approach 1    /////////

class ViewModel(
    private val interactor: Interactor,
    private val dispatchers: ICoroutineContextProvider
) {
    private val scope = CoroutineScope(SupervisorJob() + dispatchers.main)

    fun getSomething() {
        scope.launch {
            interactor.fetchSomething().either(::handleError, ::handleData)
        }
    }

    private fun handleData(i: Int) { /* set/update LiveData */ }
    private fun handleError(error: Error) { /* set/update LiveData */ }
}

class Interactor(private val dispatchers: ICoroutineContextProvider) {
    suspend fun fetchSomething(): Either<Error, Int> {
        return withContext(<http://dispatchers.io|dispatchers.io>) {
            //some very heavy operation
            Either.Result(5)
        }
    }
}