Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Multi-keys, multi-producers, single-consumer event bus backed by kotlinx.coroutines.channels.Channels

License

NotificationsYou must be signed in to change notification settings

Kotlin-Android-Open-Source/kotlin-channel-event-bus

 
 

Repository files navigation

Build and publish snapshot

Kotlin versionKotlinX Coroutines version

Hits

badgebadgebadgebadgebadgebadgebadge

TODO - TBD - WIP

Multi-keys, multi-producers, single-consumer event bus backed bykotlinx.coroutines.channels.Channels.

  • A Kotlin Multiplatform library that provides a simple event bus implementation usingkotlinx.coroutines.channels.Channels.This is useful for UI applications where you want to send events to communicate betweendifferent parts / scope of your application.

  • This bus is thread-safe to be used by multiple threads.It is safe to send events from multiple threads without any synchronization.

  • ChannelEvent.Key will be used to identify a bus for a specific type of events.Each bus has aChannel to send events to and aFlow to receive events from.

  • TheChannel is unbounded (Channel.UNLIMITED - default) or conflatedChannel.CONFLATED.TheFlow is cold and only one collector is allowed at a time.This make sure all events are consumed.

Liked some of my work? Buy me a coffee (or more likely a beer)

Buy Me A Coffee

Basic usage

// 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) }

Supported targets

  • jvm /android.
  • js (IR).
  • Darwin targets:
    • iosArm64,iosArm32,iosX64,iosSimulatorArm64.
    • watchosArm32,watchosArm64,watchosX64,watchosX86,watchosSimulatorArm64.
    • tvosX64,tvosSimulatorArm64,tvosArm64.
    • macosX64,macosArm64.

Docs

TODO - TBD - WIP

Sample

  • Android Compose sample:an Android app using Compose UI to show how to use the library.It has two nested navigation graphs:RegisterScreen andHomeScreen.

    InRegisterScreen, we have 3 steps (3 screens) to allow user to input their information, step bystep.

    • ARegisterSharedViewModel (bound toRegisterScreen navigation graph scope) is usedto hold the whole state of the registration process.It observes events from theChannelEventBus and update the state accordingly.

    • Each step screen has aViewModel to hold the state of the screen, and will send events totheChannelEventBus,then theRegisterSharedViewModel will receive those events and update the state.

Roadmap

TODO - TBD - WIP

License

TODO - TBD - WIP

About

Multi-keys, multi-producers, single-consumer event bus backed by kotlinx.coroutines.channels.Channels

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Kotlin99.1%
  • Shell0.9%

[8]ページ先頭

©2009-2025 Movatter.jp