Created
October 17, 2025 08:30
-
-
Save andhikayuana/018aaf1ceabc0c0d3e3cea27b5c275fc to your computer and use it in GitHub Desktop.
eventbus
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
| object EventBus { | |
| private val _events = MutableSharedFlow<Event>( | |
| replay = 0, // No replays, emit only to active collectors | |
| extraBufferCapacity = 1, // Buffer size of 1 to prevent backpressure issues | |
| onBufferOverflow = BufferOverflow.DROP_OLDEST // Drop oldest when buffer overflows | |
| ) | |
| val events: SharedFlow<Event> = _events.asSharedFlow() | |
| suspend fun emit(event: Event) { | |
| _events.emit(event) | |
| } | |
| sealed class Event { | |
| data class Message( | |
| val message: String, | |
| ) : Event() | |
| //TODO: add more event types as needed | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment