- Notifications
You must be signed in to change notification settings - Fork3
A Kotlin Multiplatform library that provides a simple event bus implementation using KotlinX Coroutines Channels. Multi-keys, multi-producers, single-consumer and thread-safe event bus backed by kotlinx.coroutines.channels.Channels
License
Kotlin-Multiplatform-Foundation/kotlin-channel-event-bus
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Multi-keys, multi-producers, single-consumer event bus backed bykotlinx.coroutines.channels.Channels.
A Kotlin Multiplatform library that provides a simple event bus implementation using
kotlinx.coroutines.channels.Channels.This is useful for UI applications where you want to send events to communicate betweendifferent parts / scope of your application (e.g. send results from one screen to another).This bus is thread-safe to be used by multiple threads.It is safe to send events from multiple threads without any synchronization.
ChannelEvent.Keywill be used to identify a bus for a specific type of events.Each bus has aChannelto send events to and aFlowto receive events from.The
Channelis unbounded (Channel.UNLIMITED- default) or conflatedChannel.CONFLATED.TheFlowis cold and only one collector is allowed at a time.This makes sure all events are consumed.
Author:Petrus Nguyễn Thái Học
Like some of my work? Could you buy me a coffee (or more likely a beer)?
0.x releasedocs:https://kotlin-multiplatform-foundation.github.io/kotlin-channel-event-bus/docs/0.x- Snapshot docs:https://kotlin-multiplatform-foundation.github.io/kotlin-channel-event-bus/docs/latest/
allprojects { repositories { [...] mavenCentral() }}implementation("io.github.hoc081098:channel-event-bus:0.1.0")Snapshots of the development version are available in Sonatype's snapshots repository.
- Kotlin
allprojects { repositories { [...] maven(url="https://s01.oss.sonatype.org/content/repositories/snapshots/") }}dependencies { implementation("io.github.hoc081098:channel-event-bus:0.1.1-SNAPSHOT")}- Groovy
allprojects { repositories { [...] maven { url"https://s01.oss.sonatype.org/content/repositories/snapshots/" } }}dependencies { implementation'io.github.hoc081098:channel-event-bus:0.1.1-SNAPSHOT'}// Create your event typedata classAwesomeEvent(valpayload:Int) : ChannelEvent<AwesomeEvent> {overrideval key get()=Keycompanionobject Key : ChannelEventKey<AwesomeEvent>(AwesomeEvent::class)}// Create your bus instanceval bus=ChannelEventBus()// Send events to the busbus.send(AwesomeEvent(1))bus.send(AwesomeEvent(2))bus.send(AwesomeEvent(3))// Receive events from the busbus .receiveAsFlow(AwesomeEvent)// or bus.receiveAsFlow(AwesomeEvent.Key) if you want to be explicit .collect { e:AwesomeEvent->println(e) }
jvm/android.js(IR).wasmJs.Darwintargets:iosArm64,iosX64,iosSimulatorArm64.watchosArm32,watchosArm64,watchosX64,watchosSimulatorArm64,watchosDeviceArm64.tvosX64,tvosSimulatorArm64,tvosArm64.macosX64,macosArm64.
mingwX64linuxX64,linuxArm64.androidNativeArm32,androidNativeArm64,androidNativeX86,androidNativeX64.
Android Compose sample:an Android app using Compose UI to show how to use the library.It has two nested navigation graphs:
RegisterandHome.In
Register, we have 3 steps (3 screens) to allow the user to input their information, stepbystep.A
RegisterSharedViewModel(bound toRegisternavigation graph scope) is usedto hold the whole state of the registration process.It observes events from theChannelEventBusand updates the state accordingly.Each step screen has a
ViewModelto hold the state of the screen and will send events totheChannelEventBus,then theRegisterSharedViewModelwill receive those events and update the state.
In the
Homenav graph, we have 2 screens:HomeandDetail.The
Homescreen has aHomeViewModelto hold the results received from theDetailscreen.Those result events are sent from theDetailscreen to theChannelEventBus,and theHomeViewModelwill receive those events and update the state.The
Detailscreen will send events to theChannelEventBuswhen the user clicks on the button.TheHomeViewModelwill receive those events and update the state.
Screen_recording_20231203_155312.mp4
- Support more targets:
wasm(depends on supported targets bykotlinx.coroutines) (since0.1.0). - More samples.
- More docs.
- More tests.
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/About
A Kotlin Multiplatform library that provides a simple event bus implementation using KotlinX Coroutines Channels. Multi-keys, multi-producers, single-consumer and thread-safe event bus backed by kotlinx.coroutines.channels.Channels
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.

