Skip to content

Instantly share code, notes, and snippets.

@andhikayuana
Created October 17, 2025 08:30
Show Gist options
  • Save andhikayuana/018aaf1ceabc0c0d3e3cea27b5c275fc to your computer and use it in GitHub Desktop.
Save andhikayuana/018aaf1ceabc0c0d3e3cea27b5c275fc to your computer and use it in GitHub Desktop.
eventbus
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