arrow-fx / arrow.fx.extensions.io.async / asyncF
@JvmName("asyncF") fun <A> ~~asyncF~~(k: ((Either<
Throwable
, A>) ->
Unit
) -> Kind<
ForIO
,
Unit
>):
IO
<A>
Deprecated: The IO datatype and it’s related type classes will disappear in Arrow 0.13.0. All useful operations are offered directly over suspend functions by Arrow Fx Coroutines. https://arrow-kt.io/docs/fx/async/
async variant that can suspend side effects in the provided registration function.
The passed in function is injected with a side-effectful callback for signaling the final result of an asynchronous process.
import arrow.fx.*
import arrow.fx.extensions.io.async.*
import arrow.core.*
import arrow.fx.*
import arrow.fx.typeclasses.Async
fun main(args: Array<String>) {
//sampleStart
fun <F> Async<F>.makeCompleteAndGetPromiseInAsync() =
asyncF<String> { cb: (Either<Throwable, String>) -> Unit ->
Promise.uncancellable<F, String>(this).flatMap { promise ->
promise.complete("Hello World!").flatMap {
promise.get().map { str -> cb(Right(str)) }
}
}
}
val result = IO.async().makeCompleteAndGetPromiseInAsync()
//sampleEnd
println(result)
}
See Also
Do you like Arrow?
✖