Skip to content

Instantly share code, notes, and snippets.

@InsanusMokrassar
Created September 1, 2020 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save InsanusMokrassar/8d99e4d39ca4831d6d566e14fc9423b2 to your computer and use it in GitHub Desktop.
Save InsanusMokrassar/8d99e4d39ca4831d6d566e14fc9423b2 to your computer and use it in GitHub Desktop.
Hybrid of BroadcastChannel and Flow
import kotlinx.coroutines.channels.*
import kotlinx.coroutines.flow.*
@Suppress("FunctionName")
fun <T> BroadcastFlow(
internalChannelSize: Int = Channel.BUFFERED
): BroadcastFlow<T> {
val channel = BroadcastChannel<T>(internalChannelSize)
return BroadcastFlow(
channel,
channel.asFlow()
)
}
class BroadcastFlow<T> internal constructor(
private val channel: BroadcastChannel<T>,
private val flow: Flow<T>
): Flow<T> by flow, SendChannel<T> by channel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment