arrow-fx-stm / arrow.fx.stm / STM / peek

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

TQueue.read

TQueue.tryPeek

Do you like Arrow?

Arrow Org
<