Kotlin-Multiplatform-Foundation / kotlin-channel-event-bus

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
https://kotlin-multiplatform-foundation.github.io/kotlin-channel-event-bus/docs/0.x/
Apache License 2.0
41 stars 1 forks source link
compose-multiplatform coroutines event-bus eventbus kmm kmm-jetpack-compose kmm-library kmm-mvvm kmm-sample kmm-viewmodel kmp kmp-library kmp-mvvm kmp-redux kmp-viewmodel koltin-multiplatform-event-bus kotlin-coroutines kotlin-event-bus kotlin-event-handling-android kotlin-multiplatform

kotlin-channel-event-bus 🔆

maven-central codecov Build and publish snapshot Build sample Publish Release Kotlin version KotlinX Coroutines version Hits GitHub license badge badge badge badge badge badge badge badge badge badge badge badge badge

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

Author: Petrus Nguyễn Thái Học

Like some of my work? Could you buy me a coffee (or more likely a beer)?

Buy Me A Coffee

Docs

Installation

allprojects {
  repositories {
    [...]
    mavenCentral()
  }
}
implementation("io.github.hoc081098:channel-event-bus:0.1.0")

Snapshot

Snapshots of the development version are available in Sonatype's snapshots repository. - Kotlin ```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 ```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' } ```

Basic usage

// Create your event type
data class AwesomeEvent(val payload: Int) : ChannelEvent<AwesomeEvent> {
  override val key get() = Key

  companion object Key : ChannelEventKey<AwesomeEvent>(AwesomeEvent::class)
}

// Create your bus instance
val bus = ChannelEventBus()

// Send events to the bus
bus.send(AwesomeEvent(1))
bus.send(AwesomeEvent(2))
bus.send(AwesomeEvent(3))

// Receive events from the bus
bus
  .receiveAsFlow(AwesomeEvent) // or bus.receiveAsFlow(AwesomeEvent.Key) if you want to be explicit
  .collect { e: AwesomeEvent -> println(e) }

Supported targets

Sample

https://github.com/Kotlin-Multiplatform-Foundation/kotlin-channel-event-bus/assets/36917223/80015232-d5b5-4fb2-a779-4e6113ddb8f8

Roadmap

License

                                 Apache License
                           Version 2.0, January 2004
                        http://www.apache.org/licenses/