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