Skip to content

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

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

About

A channel-like abstraction over queues

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages