Skip to content

Latest commit

 

History

History
38 lines (29 loc) · 1.08 KB

README.md

File metadata and controls

38 lines (29 loc) · 1.08 KB

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

Usage

Queues

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