getAndSet

fun <T> MutableStateFlow<T>.getAndSet(value: T): T

Sets the value to value and returns the previous value.

The swap is atomic with respect to concurrent updates. Collectors observe the new value only if it differs from the previous one, following MutableStateFlow equality conflation.