Skip to content

Instantly share code, notes, and snippets.

@pavlospt
Last active April 11, 2020 12:33
Show Gist options
  • Save pavlospt/d5d07f57eaf9e68039a6594934b3a013 to your computer and use it in GitHub Desktop.
Save pavlospt/d5d07f57eaf9e68039a6594934b3a013 to your computer and use it in GitHub Desktop.
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