Created
March 22, 2022 04:56
-
-
Save farshadrezaee/d3eebf1d9e613834de14e5f7757a0800 to your computer and use it in GitHub Desktop.
Impelment EventBus by Flow
This file contains hidden or 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
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