Aug 31, 2021
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())
}
}