arrow-fx-coroutines / arrow.fx.coroutines / Promise / tryGet

tryGet

abstract suspend fun tryGet(): A?

Tries to get the promised value, returning null if promise is not fulfilled yet. Returns A if promise is fulfilled.

import arrow.fx.coroutines.*

suspend fun main(): Unit {
  //sampleStart
  val promise = Promise<Int>()
  val empty = promise.tryGet()
  promise.complete(1)
  val full = promise.tryGet()
  //sampleEnd
  println("empty: $empty, full: $full")
}

Do you like Arrow?

Arrow Org
<