Zoltan Demant
10/05/2022, 6:11 AMscope.launch
blocks that are running in parallell.
@JvmInline
internal value class Queue(
private val trigger: MutableSharedFlow<Unit> = MutableSharedFlow(extraBufferCapacity = 8),
) {
suspend fun flush() {
trigger.emit(Unit)
}
suspend fun await() {
trigger.first()
}
}
Joffrey
10/05/2022, 6:14 AMZoltan Demant
10/05/2022, 6:20 AMZoltan Demant
10/05/2022, 6:32 AMZoltan Demant
10/05/2022, 6:42 AMflow.first()
? Just to verify that Ive understood things correctly, that also means that if I replace flow.first()
with flow.collect{ delay(5000) }
then the emit will also take 5000 ms?Joffrey
10/05/2022, 9:28 AMflush()
call will immediately complete (and the event immediately discarded) as long as no consumer is await()
-ing. And given that consumers just use first()
, it's also pretty quick when one is waiting. That said, without the buffer, flush()
callers would indeed suspend if a consumer is waiting (albeit not for long).
I was just wondering whether this was intentionalZoltan Demant
10/05/2022, 10:25 AM