arrow-fx / arrow.fx / Dequeue / takeAll

takeAll

abstract fun takeAll(): Kind<F, List<A>>

Immediately returns all available values in the Queue, and empties the Queue. It returns an emptyList when no values are available.

import arrow.fx.*
import arrow.fx.extensions.fx

//sampleStart
suspend fun main(args: Array<String>): Unit = IO.fx {
  val queue = !Queue.unbounded<Int>()
  !queue.offerAll(1, 2, 3, 4)
  val values = !queue.takeAll()
  val empty = !queue.takeAll()
  !effect { println("values: $values, empty: $empty") }
}.suspended()
//sampleEnd

For a BackpressureStrategy.Bounded, this also includes all blocking offers that are waiting to be added in the Queue.

See Also

peekAll

Do you like Arrow?

Arrow Org
<