Last active
May 16, 2024 13:10
-
-
Save MkhytarMkhoian/3f8de31600548ae43c0f4e4ed49b1911 to your computer and use it in GitHub Desktop.
This file contains 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
private fun fetchData() = intent { | |
reduce { state.copy(status = ScreenContentStatus.Loading) } | |
val fetched = coroutineScope { | |
awaitAll( | |
async { fetchUser() }, | |
async { fetchFares() }, | |
).all { it } | |
} | |
reduce { | |
state.copy( | |
status = if (fetched) { | |
ScreenContentStatus.Success | |
} else { | |
ScreenContentStatus.Failure | |
} | |
) | |
} | |
} | |
private suspend fun SimpleSyntax<FareListState, FareListEffect>.fetchFares(): Boolean = | |
executeUseCase { getFaresByIdUseCase(ryderId).asPresentation() } | |
.onSuccess { fares -> reduce { state.copy(fares = fares) } } | |
.onFailure { /* Handle error */ } | |
.isSuccess | |
private suspend fun SimpleSyntax<FareListState, FareListEffect>.fetchUser(): Boolean = | |
executeUseCase { getUserUseCase(userId).asPresentation() } | |
.onSuccess { user -> reduce { state.copy(user = user) } } | |
.isSuccess |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment