
High-performance queue abstraction with MPSC/SPSC, broadcast and one-shot channels, multiple blocking wait strategies and channel operators like map, filter, mapNotNull.
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.
map, mapNotNull, filter
Supported Kotlin Multiplatform targets are JVM, Android, JavaScript (Node.js), macOS ARM64, and iOS (ARM64, x64, and simulator ARM64).
The common API exposes non-blocking offer() and poll() operations. Synchronous take(), forEach(), and blocking
strategy member functions are available only from JVM/Android source sets, including ordinary Java calls such as
receiver.withBusySpinBlockingStrategy().take(). JavaScript and Apple targets should use the suspending APIs from
channels-core when they need to wait for values.
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.4"))
// For the latest snapshot (requires the snapshot repository above)
// implementation(platform("io.kriptal.channels:channels-bom:1.0.5-SNAPSHOT"))
// Core includes non-blocking queues and common coroutine-based receivers
implementation("io.kriptal.channels:channels-core")
}val channel = QueueChannel.mpscUnbounded<Int>()
channel.offer(1)
channel.offer(2)
channel.offer(3)
// iterate over the channel, until the channel is closed.
// JVM/Android only: blocks the current thread
channel.forEach { element ->
println(element)
}
// common suspending API from channels-core
channel.forEachSuspend { element ->
println(element)
}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.
map, mapNotNull, filter
Supported Kotlin Multiplatform targets are JVM, Android, JavaScript (Node.js), macOS ARM64, and iOS (ARM64, x64, and simulator ARM64).
The common API exposes non-blocking offer() and poll() operations. Synchronous take(), forEach(), and blocking
strategy member functions are available only from JVM/Android source sets, including ordinary Java calls such as
receiver.withBusySpinBlockingStrategy().take(). JavaScript and Apple targets should use the suspending APIs from
channels-core when they need to wait for values.
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.4"))
// For the latest snapshot (requires the snapshot repository above)
// implementation(platform("io.kriptal.channels:channels-bom:1.0.5-SNAPSHOT"))
// Core includes non-blocking queues and common coroutine-based receivers
implementation("io.kriptal.channels:channels-core")
}val channel = QueueChannel.mpscUnbounded<Int>()
channel.offer(1)
channel.offer(2)
channel.offer(3)
// iterate over the channel, until the channel is closed.
// JVM/Android only: blocks the current thread
channel.forEach { element ->
println(element)
}
// common suspending API from channels-core
channel.forEachSuspend { element ->
println(element)
}