arrow-fx / arrow.fx / Queue / dropping

dropping

fun <F, A> dropping(capacity: Int, CF: Concurrent<F>): Kind<F, Queue<F, A>>

Create a Queue with BackpressureStrategy.Dropping.

Offering to a dropping queue at capacity will cause the offered value to be discarded.

import arrow.fx.*
import arrow.fx.extensions.fx
import arrow.fx.extensions.io.concurrent.concurrent

suspend fun main(args: Array<String>): Unit = IO.fx {
  val capacity = 2
  val q = !Queue.dropping<ForIO, Int>(capacity, IO.concurrent())
  !q.offer(42)
  !q.offer(43)
  !q.offer(44) // <-- This `offer` exceeds the capacity and will be dropped immediately
  val fortyTwo   = !q.take()
  val fortyThree = !q.take()
  !q.offer(45)
  val fortyFive  = !q.take()
  !effect { println(listOf(fortyTwo, fortyThree, fortyFive)) }
}.suspended()

Do you like Arrow?

Arrow Org
<