--

Can't you just change your trigger to a channel with receiveAsFlow to ensure that it never re-emits when resubscribed?

eg.

private val triggerChannel = Channel<String?>()
val results = triggerChannel.receiveAsFlow()
.filterNotNull()
.mapLatest { query -> "Fake repo response " + query }
.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(),
initialValue = ""
)

fun trigger() {
viewModelScope.launch {
triggerChannel.send(UUID.randomUUID().toString())
}
}

--

--

Michael Ferguson
Michael Ferguson

Written by Michael Ferguson

Android software developer. Views and opinions expressed are my own and not that of my employer.

Responses (1)