arrow-fx / arrow.fx / Promise / tryComplete
abstract fun tryComplete(a: A): Kind<F,
Boolean
>
Try to complete, or fulfill, the promise with the specified value A.
Returns true
if the promise successfully completed, false
otherwise.
import arrow.fx.*
import arrow.fx.extensions.io.async.async
import arrow.fx.extensions.io.monad.flatMap
fun main(args: Array<String>) {
//sampleStart
val promise = Promise.uncancellable<ForIO, Int>(IO.async())
promise.flatMap { p ->
p.tryComplete(1)
}.unsafeRunSync() == true
promise.flatMap { p ->
p.complete(1).flatMap {
p.tryComplete(2)
}
}.unsafeRunSync() == false
//sampleEnd
}
Do you like Arrow?
✖