Created
June 10, 2021 19:32
-
-
Save carotkut94/05dd678b9078d10b7fa6debda9d55237 to your computer and use it in GitHub Desktop.
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
@ExperimentalCoroutinesApi | |
object EventBus { | |
val bus: BroadcastChannel<Any> = BroadcastChannel(Channel.CONFLATED) | |
suspend fun send(o: Any) = bus.send(o) | |
inline fun <reified T> asChannel(): ReceiveChannel<T> { | |
return bus.openSubscription().filter { it is T }.map { it as T } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment