From c75c7c9823be67fbc0eea1934a38b6e5302603e3 Mon Sep 17 00:00:00 2001 From: Silas Della Contrada Date: Sat, 10 Aug 2024 22:34:07 +0200 Subject: [PATCH] feat: (buffersink) use shared flow --- .../dev/silenium/libs/flows/buffer/BufferSink.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/dev/silenium/libs/flows/buffer/BufferSink.kt b/src/main/kotlin/dev/silenium/libs/flows/buffer/BufferSink.kt index ca98449..11170c8 100644 --- a/src/main/kotlin/dev/silenium/libs/flows/buffer/BufferSink.kt +++ b/src/main/kotlin/dev/silenium/libs/flows/buffer/BufferSink.kt @@ -2,9 +2,9 @@ package dev.silenium.libs.flows.buffer import dev.silenium.libs.flows.api.FlowItem import dev.silenium.libs.flows.api.Sink -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.flow.SharedFlow +import kotlinx.coroutines.flow.asSharedFlow class BufferSink(vararg pads: Pair) : Sink { private val inputMetadata_: MutableMap = pads.toMap().toMutableMap() @@ -12,8 +12,8 @@ class BufferSink(vararg pads: Pair) : Sink { private val buffer_: MutableMap>> = mutableMapOf() val buffer: Map>> by ::buffer_ - private val flow_ = MutableStateFlow>>>(emptyMap()) - val flow: StateFlow>>> = flow_.asStateFlow() + private val flow_ = MutableSharedFlow>>>(replay = 1) + val flow: SharedFlow>>> = flow_.asSharedFlow() override suspend fun receive(item: FlowItem): Result { buffer_.getOrPut(item.pad, ::mutableListOf).add(item)