peek

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.

See also

for a version that removes the front element.

for a version that does not retry.