Last active
April 11, 2020 12:33
-
-
Save pavlospt/d5d07f57eaf9e68039a6594934b3a013 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
class OurViewModel: ViewModel() { | |
private val _intentChannel = ConflatedBroadcastChannel<OurViewIntent>() | |
init { | |
_intentChannel | |
.asFlow() | |
.onEach { viewIntent -> | |
when (viewIntent) { | |
OurViewIntent.Refresh -> refreshData() | |
} | |
} | |
.launchIn(viewModelScope) | |
} | |
suspend fun processIntent(intent: OurViewIntent) = | |
_intentChannel.send(intent) | |
private suspend fun refreshData() { | |
// Do some work to refresh our data here | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment