Is it possible to rewrite the following
ViewModel
private extensions function into a public, standalone function which can be used by all ViewModels in a project?
private fun <E> SendChannel<E>.sendOneTimeEvent(event: E) {
viewModelScope.launch {
send(event)
}
}
I thought, it might work by leveraging the experimental
context receivers feature
-Xcontext-receivers
.
context(ViewModel)
fun <E> SendChannel<E>.sendOneTimeEvent(event: E) {
viewModelScope.launch {
send(event)
}
}
But this raises an error at call site:
> No required context receiver found: Cxt { context(androidx.lifecycle.ViewModel) public fun
E kotlinx.coroutines.channels.SendChannel
E.sendOneTimeEvent(event: E)