arrow-fx-coroutines / arrow.fx.coroutines / Environment
interface ~~Environment~~
Deprecated: Use KotlinX structured concurrency as unsafe Environment to launch side-effects from non-suspending code
An Environment can run suspend programs using startCoroutine and startCoroutineCancellable.
An Environment runs on a certain CoroutineContext which is used to start the programs on. Since coroutines always return where they were started, this CoroutineContext also defines where you return after operators like sleep or evalOn. Therefore it’s advised to always run on ComputationPool which is the default setting.
Environment also has an asyncErrorHandler, which by default redirects to Throwable.printStackTrace. No user flow errors will ever be sent here. CancelToken exceptions might bubble up here when they cannot be redirect to the user.
This Environment is meant to be used in Java frameworks, or frameworks that do not expose suspend edge-points.
This contract could be elaborated on Android to provide automatic cancellation on Android LifecycleOwner.
ctx | Start CoroutineContext of the programs ran using startCoroutine and startCoroutineCancellable.abstract val ctx: CoroutineContext |
asyncErrorHandler | The async error handler is reserved for rare exceptions; e.g. when an error occurs after the completion of a kotlin.coroutines.Continuation, or when an error occurs when triggering a CancelToken.abstract fun asyncErrorHandler(e: Throwable ): Unit |
unsafeRunAsync | Execution strategy that will immediately return and perform the program’s work without blocking the current thread. This operation runs uncancellable.open fun unsafeRunAsync(fa: suspend () -> Unit ): Unit abstract fun <A> unsafeRunAsync(fa: suspend () -> A, e: ( Throwable ) -> Unit , a: (A) -> Unit ): Unit |
unsafeRunAsyncCancellable | Execution strategy that will immediately return and perform the program’s work without blocking the current thread. Runs the operation fa in a cancellable way. Execution can be cancelled by invoking the returned Disposable.open fun unsafeRunAsyncCancellable(fa: suspend () -> Unit ): Disposable abstract fun <A> unsafeRunAsyncCancellable(fa: suspend () -> A, e: ( Throwable ) -> Unit , a: (A) -> Unit ): Disposable |
unsafeRunSync | Execution strategy that will block the current thread that’s waiting for the program to yield a value.abstract fun <A> unsafeRunSync(fa: suspend () -> A): A |
invoke | operator fun invoke(ctx: CoroutineContext = Dispatchers.Default): Environment |
Do you like Arrow?
✖