//arrow-fx-stm/arrow.fx.stm/STM/peek
common open fun <A> TQueue<A>.peek(): A
Read the front element of a TQueue without removing it.
import arrow.fx.stm.TQueue
import arrow.fx.stm.atomically
suspend fun main() {
//sampleStart
val tq = TQueue.new<Int>()
val result = atomically {
tq.write(2)
tq.peek()
}
//sampleEnd
println("Result $result")
println("Items in queue ${atomically { tq.flush() }}")
}
This function retries if the TQueue is empty.
common
arrow.fx.stm.STM | for a version that does not retry. |
Do you like Arrow?
✖