arrow-fx-coroutines / arrow.fx.coroutines / ConcurrentVar / tryTake

tryTake

abstract suspend fun tryTake(): A?

Tries to take the value of ConcurrentVar, returns a value immediately if the ConcurrentVar is not empty, or null otherwise.

import arrow.fx.coroutines.*

suspend fun main(): Unit {
  //sampleStart
  val mvar = ConcurrentVar(5)
  val value = mvar.tryTake()
  val empty = mvar.tryTake()
  //sampleEnd
  println("value: $value, empty: $empty")
}

Do you like Arrow?

Arrow Org
<