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.
- 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
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")
}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)
}