arrow-fx-stm / arrow.fx.stm / STM / tryPeek

tryPeek

open fun <A> TQueue<A>.tryPeek(): A?

Same as TQueue.peek except it returns null if the TQueue is empty.

import arrow.fx.stm.TQueue
import arrow.fx.stm.atomically

suspend fun main() {
  //sampleStart
  val tq = TQueue.new<Int>()
  val result = atomically {
    tq.tryPeek()
  }
  //sampleEnd
  println("Result $result")
  println("Items in queue ${atomically { tq.flush() }}")
}

This function never retries.

See Also

TQueue.tryRead

TQueue.peek

Do you like Arrow?

Arrow Org
<