Update the SnackbarRelayManager (#5317)

This commit is contained in:
David Perez
2025-06-06 13:28:08 -05:00
committed by GitHub
parent e1cd813445
commit beb4c533c8
26 changed files with 180 additions and 236 deletions

View File

@@ -1,6 +1,7 @@
package com.bitwarden.core.data.repository.util
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.first
/**
* Creates a [MutableSharedFlow] with a buffer of [Int.MAX_VALUE] and the given [replay] count.
@@ -12,3 +13,17 @@ fun <T> bufferedMutableSharedFlow(
replay = replay,
extraBufferCapacity = Int.MAX_VALUE,
)
/**
* Emits a [value] to this shared flow, suspending until there is at least one subscriber.
*/
suspend fun <T> MutableSharedFlow<T>.emitWhenSubscribedTo(value: T) {
// We have subscribers, so emit now.
if (subscriptionCount.value > 0) {
emit(value = value)
return
}
// We are going to wait until there is at least one subscriber, then emit.
subscriptionCount.first { it > 0 }
emit(value = value)
}