Created
October 4, 2020 20:02
-
-
Save Kiolk/422fb1d638b18b28af3fd6186b3c5808 to your computer and use it in GitHub Desktop.
Use coroutine outside viewModelScope
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GoalDataSource(private val getReactGoalsUseCase: GetReactGoalsUseCase) : | |
PositionalDataSource<Goal>() { | |
override fun loadRange(params: LoadRangeParams, callback: LoadRangeCallback<Goal>) { | |
CoroutineScope(Dispatchers.Main).launch { | |
getReactGoalsUseCase.invoke(this, GetReactGoalsUseCase.Param(params.startPosition)) { | |
it.either({}, { goals: List<Goal> -> | |
callback.onResult(goals) | |
}) | |
} | |
} | |
} | |
override fun loadInitial(params: LoadInitialParams, callback: LoadInitialCallback<Goal>) { | |
CoroutineScope(Dispatchers.Main).launch { | |
getReactGoalsUseCase.invoke( | |
this, | |
GetReactGoalsUseCase.Param(params.requestedStartPosition) | |
) { | |
it.either({}, { goals: List<Goal> -> | |
callback.onResult(goals, 0) | |
}) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment