Skip to content

Instantly share code, notes, and snippets.

@farshadrezaee
Created March 22, 2022 04:56
Show Gist options
  • Save farshadrezaee/d3eebf1d9e613834de14e5f7757a0800 to your computer and use it in GitHub Desktop.
Save farshadrezaee/d3eebf1d9e613834de14e5f7757a0800 to your computer and use it in GitHub Desktop.
Impelment EventBus by Flow
class EventBus{
private val event = MutableSharedFlow<Any>()
fun post(o: Any) = GlobalScope.launch(Dispatchers.IO) {
event.emit(o)
}
inline fun <reified T> subscribeOn(): Flow<T> = event.asSharedFlow()
.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