Created
September 1, 2020 07:12
-
-
Save InsanusMokrassar/8d99e4d39ca4831d6d566e14fc9423b2 to your computer and use it in GitHub Desktop.
Hybrid of BroadcastChannel and Flow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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