
Lightweight, coroutine-native in-process event bus enabling type-safe publish/subscribe with cancellable subscriptions and scope-bound structured concurrency for simple asynchronous event delivery.
A lightweight, coroutine-native in-process event bus for Kotlin Multiplatform.
Add the dependency to your project:
dependencies {
implementation("io.github.briangits.events:events:<version>")
}Then create an event bus, publish events, and subscribe to them:
val bus = Events()
val subscription = bus.subscribe<UserLoggedIn> { event ->
println("User logged in: ${event.username}")
}
bus.publish { UserLoggedIn("janedoe") }
subscription.cancel()data class UserLoggedIn(val username: String)val bus = Events()
val subscription = bus.subscribe<UserLoggedIn> { event ->
println("User logged in: ${event.username}")
}A subscribe() returns a Job that can be canceled when no longer needed.
subscription.cancel()bus.publish { UserLoggedIn("janedoe") }Subscriptions can be attached to an existing CoroutineScope
and are canceled when the scope is canceled
val scope = CoroutineScope(Dispatchers.Default)
val subscription = bus.subscribe<UserLoggedIn>(scope) { event ->
println("User logged in: ${event.username}")
}
// Cancelling the scope cancels the subscription
scope.cancel()A lightweight, coroutine-native in-process event bus for Kotlin Multiplatform.
Add the dependency to your project:
dependencies {
implementation("io.github.briangits.events:events:<version>")
}Then create an event bus, publish events, and subscribe to them:
val bus = Events()
val subscription = bus.subscribe<UserLoggedIn> { event ->
println("User logged in: ${event.username}")
}
bus.publish { UserLoggedIn("janedoe") }
subscription.cancel()data class UserLoggedIn(val username: String)val bus = Events()
val subscription = bus.subscribe<UserLoggedIn> { event ->
println("User logged in: ${event.username}")
}A subscribe() returns a Job that can be canceled when no longer needed.
subscription.cancel()bus.publish { UserLoggedIn("janedoe") }Subscriptions can be attached to an existing CoroutineScope
and are canceled when the scope is canceled
val scope = CoroutineScope(Dispatchers.Default)
val subscription = bus.subscribe<UserLoggedIn>(scope) { event ->
println("User logged in: ${event.username}")
}
// Cancelling the scope cancels the subscription
scope.cancel()