arrow-fx / arrow.fx / Promise / get
abstract fun get(): Kind<F, A>
Get the promised value. Suspending the Fiber running the action until the result is available.
import arrow.fx.*
import arrow.fx.typeclasses.*
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.get()
} //Never ends since is uncancellable
promise.flatMap { p ->
p.complete(1).flatMap {
p.get()
}
}.unsafeRunSync() == IO.just(1).unsafeRunSync()
//sampleEnd
}
Do you like Arrow?
✖