arrow-fx-coroutines / arrow.fx.coroutines / Promise / complete
abstract suspend fun complete(a: A): Either<AlreadyFulfilled,
Unit
>
Completes, or fulfills, the promise with the specified value A. Returns Promise.AlreadyFulfilled in Either.Left if the promise is already fulfilled.
import arrow.fx.coroutines.*
suspend fun main(): Unit {
//sampleStart
val p = Promise<Int>()
p.complete(1)
val r1 = p.get()
val failed = p.complete(2)
val r2 = p.get()
//sampleEnd
println("r1: $r1, failed: $failed, r2: $r2")
}
Do you like Arrow?
✖