Skip to content

Instantly share code, notes, and snippets.

@Kiolk
Created October 4, 2020 20:48
Show Gist options
  • Save Kiolk/6a1efd421cc0936d499c3f0756c35caf to your computer and use it in GitHub Desktop.
Save Kiolk/6a1efd421cc0936d499c3f0756c35caf to your computer and use it in GitHub Desktop.
Example coroutine with Flow
abstract class BaseFlowUseCase<out Type, in Params> {
abstract suspend fun execute(param: Params): Flow<Type>
}
override suspend fun getNumberInvites(): Flow<Int> {
return local.getNumberInvites()
}
override suspend fun getNumberInvites(): Flow<Int> {
return sharedPreferences.observeKey(INVITATIONS_KEY, 0)
}
private fun subScribeBadgeListeners() {
viewModelScope.launch {
getNumberInvitesUseCase.execute(GetNumberInvitesUseCase.Param()).collect {
_invites.value = it
}
}
viewModelScope.launch {
getNumberMessagesUseCase.execute(GetNumberMessagesUseCase.Param()).collect {
_messages.value = it
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment