Skip to content

Kotlin Multiplatform channel-like abstraction over queues. Supports JVM and iOS targets

Notifications You must be signed in to change notification settings

Kr1ptal/channels-kt

Repository files navigation

channels-kt

channels-kt is a high-performance abstraction over queues. It provides different flavors of queues, such as MPSC (multiple-producer, single-consumer) and SPSC (single-producer, single-consumer). It also contains specialized implementations of channels, such as BroadcastChannel and OneShotChannel.

Features

  • MPSC (multiple-producer, single-consumer) queues
  • SPSC (single-producer, single-consumer) queues
  • Broadcast channels
  • One-shot channels
  • Different blocking wait strategies: sleeping, parking, yielding, busy spinning, suspending (coroutines)
  • Channel operators: map, mapNotNull, filter

🚀 Quickstart

All releases are published to Maven Central. Changelog of each release can be found under Releases.

It's recommended to define BOM platform dependency to ensure that all artifacts are compatible with each other.

// Define a maven repository where the library is published
repositories {
    mavenCentral()

    // for snapshot versions, use the following repository
    //maven { url = uri("https://central.sonatype.com/repository/maven-snapshots/") }
}

dependencies {
    // Define a BOM and its version
    implementation(platform("io.kriptal.channels:channels-bom:1.0.0"))

    // Define any required artifacts without version
    implementation("io.kriptal.channels:channels-core")
    implementation("io.kriptal.channels:channels-coroutines")
}

Queue-based Channels

val channel = QueueChannel.mpscUnbounded<Int>()
channel.offer(1)
channel.offer(2)
channel.offer(3)

// iterate over the channel, until the channel is closed. 

// blocking the current thread
channel.forEach { element ->
    println(element)
}

// needs "channels-coroutines" dependency
channel.forEachSuspend { element ->
    println(element)
}

About

Kotlin Multiplatform channel-like abstraction over queues. Supports JVM and iOS targets

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages