Created
October 4, 2020 20:48
-
-
Save Kiolk/6a1efd421cc0936d499c3f0756c35caf to your computer and use it in GitHub Desktop.
Example coroutine with Flow
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
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