arrow-fx / arrow.fx / Dequeue / tryTake
abstract fun tryTake(): Kind<F, Option<A>>
Attempts to take a value from the Queue if one is available, this method is guaranteed not to semantically block. It returns immediately an Option with either None or a value wrapped in Some.
import arrow.fx.*
import arrow.fx.extensions.fx
//sampleStart
suspend fun main(args: Array<String>): Unit = IO.fx {
val queue = !Queue.unbounded<Int>()
val none = !queue.tryTake()
!queue.offer(1)
val one = !queue.tryTake()
val none2 = !queue.tryTake()
!effect { println("none: $none, one $one, none2: $none2") }
}.suspended()
//sampleEnd
See Also
Do you like Arrow?
✖