Skip to content

Commit

Permalink
feat: add constructor to IdMessageFlow
Browse files Browse the repository at this point in the history
  • Loading branch information
xfqwdsj committed Apr 13, 2024
1 parent fe917bb commit 4cb3052
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
package xyz.xfqlittlefan.fhraise.browser

import android.content.Context
import kotlinx.coroutines.flow.MutableSharedFlow
import xyz.xfqlittlefan.fhraise.flow.IdMessageFlow
import java.util.*

val newBrowserFlowId get() = UUID.randomUUID().toString()
val browserFlow = IdMessageFlow<String, BrowserMessage>(MutableSharedFlow(replay = 1, extraBufferCapacity = 1))
val browserFlow = IdMessageFlow<String, BrowserMessage>(1, 1)

sealed class BrowserMessage {
data object Ready : BrowserMessage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@

package xyz.xfqlittlefan.fhraise.flow

import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.*

open class IdMessageFlow<I, V>(
mutableSharedFlow: MutableSharedFlow<Pair<I, V>> = MutableSharedFlow()
) : MutableSharedFlow<Pair<I, V>> by mutableSharedFlow {
constructor(
replay: Int = 0, extraBufferCapacity: Int = 0, onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND
) : this(MutableSharedFlow(replay, extraBufferCapacity, onBufferOverflow))

suspend inline fun collect(id: I, block: FlowCollector<V>) =
block.emitAll(filter { it.first == id }.map { it.second })

Expand Down

0 comments on commit 4cb3052

Please sign in to comment.