跳到主要内容

compose-eventbus

自动收集自 lib/compose/compose-eventbus/README.md

Small in-process event bus for Compose and shared coroutine flows.

What It Provides

  • EventBus.emit(event) to publish events
  • EventBus.events<T>() to observe a typed stream
  • EventBus.consumer<T> { ... } for suspend consumers
  • Optional bridge from network-starter HTTP error responses into the event bus

Basic Usage

launch {
EventBus.emit(UserLoggedIn("u-1"))
}

launch {
EventBus.consumer<UserLoggedIn> {
println(id)
}
}

HTTP Response Bridge

If this module and network-starter are both in the app, EventBusHttpResponseHandler is registered through Koin SPI.

That means failed HttpResponse events from the shared HTTP client can be consumed directly:

launch {
EventBus.consumer<HttpResponse> {
println(status)
}
}

Notes

  • The bus is type-based. Different event classes use different flows.
  • MutableSharedFlow is created lazily with extraBufferCapacity = 64.

Maven / Gradle

已发布至 Maven Central。

implementation("site.addzero:compose-eventbus:latest version")
<dependency>
<groupId>site.addzero</groupId>
<artifactId>compose-eventbus</artifactId>
<version>latest version</version>
</dependency>