Skip to content

Instantly share code, notes, and snippets.

@carotkut94
Created June 10, 2021 19:32
Show Gist options
  • Save carotkut94/05dd678b9078d10b7fa6debda9d55237 to your computer and use it in GitHub Desktop.
Save carotkut94/05dd678b9078d10b7fa6debda9d55237 to your computer and use it in GitHub Desktop.
@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