arrow-fx-coroutines / arrow.fx.coroutines

Package arrow.fx.coroutines

Types

Atomic Creates an AtomicRef with a initial value of A.interface Atomic<A>
AtomicBooleanW class AtomicBooleanW
AtomicIntW class AtomicIntW
AtomicRefW class AtomicRefW<A>
CancellableContinuation Type to constraint startCoroutineCancellable to the CancellableContinuation constructor.interface ~~CancellableContinuation~~<A> : Continuation<A>
CancelToken Inline marker to mark a CancelToken, This allows for clearer APIs in functions that expect a CancelToken to be returned.class ~~CancelToken~~
CircuitBreaker class CircuitBreaker
ConcurrentVar ConcurrentVar is a mutable concurrent safe variable which is either empty or contains a single value of type A. It behaves as a single element arrow.fx.coroutines.stream.concurrent.Queue. When trying to put or take, it will suspend when it is respectively isEmpty or isNotEmpty.interface ~~ConcurrentVar~~<A>
Disposable typealias ~~Disposable~~ = () -> Unit
Duration data class ~~Duration~~
Environment An Environment can run suspend programs using startCoroutine and startCoroutineCancellable.interface ~~Environment~~
ExitCase sealed class ExitCase
Fiber Fiber represents a pure value that contains a running suspend () -> A.interface ~~Fiber~~<A>
IQueue Port of scala.collection.immutable.Queuedata class ~~IQueue~~<A> : Iterable<A>
Platform object Platform
Promise A Promise is commonly used to provide and receive a value from 2 different threads. Since Promise can only be completed once unlike ConcurrentVar, we can consider it a synchronization primitive.interface ~~Promise~~<A>
Race3 sealed class Race3<out A, out B, out C>
RacePair typealias ~~RacePair~~<A, B> = Either<Pair<A, Fiber<B>>, Pair<Fiber<A>, B>>
RaceTriple sealed class ~~RaceTriple~~<A, B, C>
Resource Resource models resource allocation and releasing. It is especially useful when multiple resources that depend on each other need to be acquired and later released in reverse order.sealed class Resource<out A>
Schedule Retrying and repeating effectssealed class Schedule<Input, Output>
Semaphore A counting Semaphore has a non-negative number of permits available. It is used to track how many permits are in-use, and to automatically await a number of permits to become available.interface ~~Semaphore~~
Use Marker for suspend () -> A to be marked as the Use action of a Resource. Offers a convenient DSL to use Resource for simple resources.class Use<A>

Extensions for External Classes

arrow.core.Either  
kotlin.collections.Iterable  
kotlin.coroutines.SuspendFunction0  
kotlin.Int  
kotlin.Long  
kotlin.Throwable  
kotlinx.coroutines.Deferred  
kotlinx.coroutines.flow.Flow  

Properties

ComputationPool A CoroutineContext to run non-blocking suspending code.val ~~ComputationPool~~: CoroutineContext
IOPool Creates a thread pool that creates new threads as needed, but will reuse previously constructed threads when they are available.val ~~IOPool~~: CoroutineContext

Functions

bracket Describes a task with safe resource acquisition and release in the face of errors and interruption. It would be the equivalent of an async capable try/catch/finally statements in mainstream imperative languages for resource acquisition and release.suspend fun <A, B> bracket(acquire: suspend () -> A, use: suspend (A) -> B, release: suspend (A) -> Unit): B
bracketCase A way to safely acquire a resource and release in the face of errors and cancellation. It uses ExitCase to distinguish between different exit cases when releasing the acquired resource.suspend fun <A, B> bracketCase(acquire: suspend () -> A, use: suspend (A) -> B, release: suspend (A, ExitCase) -> Unit): B
cancelBoundary Inserts a cancellable boundary.suspend fun ~~cancelBoundary~~(): Unit
cancellable Creates a cancellable suspend function that executes an asynchronous process on evaluation. This combinator can be used to wrap callbacks or other similar impure code that requires cancellation code.suspend fun <A> ~~cancellable~~(cb: ((Result<A>) -> Unit) -> CancelToken): A
CancellableContinuation Constructor for CancellableContinuationfun <A> ~~CancellableContinuation~~(ctx: CoroutineContext = Dispatchers.Default, resumeWith: (Result<A>) -> Unit): CancellableContinuation<A>
cancellableF Creates a cancellable suspend function that executes an asynchronous process on evaluation. This combinator can be used to wrap callbacks or other similar impure code that requires cancellation code.suspend fun <A> ~~cancellableF~~(cb: suspend ((Result<A>) -> Unit) -> CancelToken): A
evalOn Executes a task on context and comes back to the original CoroutineContext.suspend fun <T> ~~evalOn~~(context: CoroutineContext, block: suspend () -> T): T
ForkAndForget Launches a new suspendable cancellable coroutine within a Fiber. You can Fiber.join or Fiber.cancel the computation.suspend fun <A> ~~ForkAndForget~~(ctx: CoroutineContext = Dispatchers.Default, f: suspend () -> A): Fiber<A>
ForkConnected Launches a new suspendable cancellable coroutine within a Fiber. It does so by connecting the created Fiber’s cancellation to the callers suspend scope. If the caller of ForkConnected gets cancelled, then this Fiber will also get cancelled.suspend fun <A> ~~ForkConnected~~(ctx: CoroutineContext = Dispatchers.Default, f: suspend () -> A): Fiber<A>
ForkScoped Launches a new suspendable cancellable coroutine within a Fiber. It does so by connecting the created Fiber’s cancellation to the provided interruptWhen. If the interruptWhen signal gets triggered, then this Fiber will get cancelled.suspend fun <A> ~~ForkScoped~~(ctx: CoroutineContext = Dispatchers.Default, interruptWhen: suspend () -> Unit, f: suspend () -> A): Fiber<A>
guarantee Guarantees execution of a given finalizer after fa regardless of success, error or cancellation.suspend fun <A> guarantee(fa: suspend () -> A, finalizer: suspend () -> Unit): A
guaranteeCase Guarantees execution of a given finalizer after fa regardless of success, error or cancellation, allowing for differentiating between exit conditions with the ExitCase argument of the finalizer.suspend fun <A> guaranteeCase(fa: suspend () -> A, finalizer: suspend (ExitCase) -> Unit): A
never suspend fun <A> never(): A
onCancel Registers an onCancel handler after fa. onCancel is guaranteed to be called in case of cancellation, otherwise it’s ignored.suspend fun <A> onCancel(fa: suspend () -> A, onCancel: suspend () -> Unit): A
parMapN Runs fa, fb in parallel on Dispatchers.Default and combines their results using the provided function.suspend fun <A, B, C> ~~parMapN~~(fa: suspend () -> A, fb: suspend () -> B, f: suspend (A, B) -> C): C
Runs fa, fb in parallel on ctx and combines their results using the provided function.suspend fun <A, B, C> ~~parMapN~~(ctx: CoroutineContext = EmptyCoroutineContext, fa: suspend () -> A, fb: suspend () -> B, f: suspend (A, B) -> C): C
Runs fa, fb, fc in parallel on Dispatchers.Default and combines their results using the provided function.suspend fun <A, B, C, D> ~~parMapN~~(fa: suspend () -> A, fb: suspend () -> B, fc: suspend () -> C, f: suspend (A, B, C) -> D): D
Runs fa, fb, fc in parallel on ctx and combines their results using the provided function.suspend fun <A, B, C, D> ~~parMapN~~(ctx: CoroutineContext = EmptyCoroutineContext, fa: suspend () -> A, fb: suspend () -> B, fc: suspend () -> C, f: suspend (A, B, C) -> D): D
Runs fa, fb, fc, fd in parallel on Dispatchers.Default and combines their results using the provided function.suspend fun <A, B, C, D, E> ~~parMapN~~(fa: suspend () -> A, fb: suspend () -> B, fc: suspend () -> C, fd: suspend () -> D, f: suspend (A, B, C, D) -> E): E
Runs fa, fb, fc, fd in parallel on ctx and combines their results using the provided function.suspend fun <A, B, C, D, E> ~~parMapN~~(ctx: CoroutineContext = EmptyCoroutineContext, fa: suspend () -> A, fb: suspend () -> B, fc: suspend () -> C, fd: suspend () -> D, f: suspend (A, B, C, D) -> E): E
Runs fa, fb, fc, fd, fe in parallel on Dispatchers.Default and combines their results using the provided function.suspend fun <A, B, C, D, E, F> ~~parMapN~~(fa: suspend () -> A, fb: suspend () -> B, fc: suspend () -> C, fd: suspend () -> D, fe: suspend () -> E, f: suspend (A, B, C, D, E) -> F): F
Runs fa, fb, fc, fd, fe in parallel on ctx and combines their results using the provided function.suspend fun <A, B, C, D, E, F> ~~parMapN~~(ctx: CoroutineContext = EmptyCoroutineContext, fa: suspend () -> A, fb: suspend () -> B, fc: suspend () -> C, fd: suspend () -> D, fe: suspend () -> E, f: suspend (A, B, C, D, E) -> F): F
Runs fa, fb, fc, fd, fe, ff in parallel on Dispatchers.Default and combines their results using the provided function.suspend fun <A, B, C, D, E, F, G> ~~parMapN~~(fa: suspend () -> A, fb: suspend () -> B, fc: suspend () -> C, fd: suspend () -> D, fe: suspend () -> E, ff: suspend () -> F, f: suspend (A, B, C, D, E, F) -> G): G
Runs fa, fb, fc, fd, fe, ff in parallel on ctx and combines their results using the provided function.suspend fun <A, B, C, D, E, F, G> ~~parMapN~~(ctx: CoroutineContext = EmptyCoroutineContext, fa: suspend () -> A, fb: suspend () -> B, fc: suspend () -> C, fd: suspend () -> D, fe: suspend () -> E, ff: suspend () -> F, f: suspend (A, B, C, D, E, F) -> G): G
Runs fa, fb, fc, fd, fe, ff, fg in parallel on Dispatchers.Default and combines their results using the provided function.suspend fun <A, B, C, D, E, F, G, H> ~~parMapN~~(fa: suspend () -> A, fb: suspend () -> B, fc: suspend () -> C, fd: suspend () -> D, fe: suspend () -> E, ff: suspend () -> F, fg: suspend () -> G, f: suspend (A, B, C, D, E, F, G) -> H): H
Runs fa, fb, fc, fd, fe, ff, fg in parallel on ctx and combines their results using the provided function.suspend fun <A, B, C, D, E, F, G, H> ~~parMapN~~(ctx: CoroutineContext = EmptyCoroutineContext, fa: suspend () -> A, fb: suspend () -> B, fc: suspend () -> C, fd: suspend () -> D, fe: suspend () -> E, ff: suspend () -> F, fg: suspend () -> G, f: suspend (A, B, C, D, E, F, G) -> H): H
Runs fa, fb, fc, fd, fe, ff, fg, fh in parallel on Dispatchers.Default and combines their results using the provided function.suspend fun <A, B, C, D, E, F, G, H, I> ~~parMapN~~(fa: suspend () -> A, fb: suspend () -> B, fc: suspend () -> C, fd: suspend () -> D, fe: suspend () -> E, ff: suspend () -> F, fg: suspend () -> G, fh: suspend () -> H, f: suspend (A, B, C, D, E, F, G, H) -> I): I
Runs fa, fb, fc, fd, fe, ff, fg, fh in parallel on ctx and combines their results using the provided function.suspend fun <A, B, C, D, E, F, G, H, I> ~~parMapN~~(ctx: CoroutineContext = EmptyCoroutineContext, fa: suspend () -> A, fb: suspend () -> B, fc: suspend () -> C, fd: suspend () -> D, fe: suspend () -> E, ff: suspend () -> F, fg: suspend () -> G, fh: suspend () -> H, f: suspend (A, B, C, D, E, F, G, H) -> I): I
parTupledN Runs fa, fb in parallel on Dispatchers.Default and combines their results into Pair.suspend fun <A, B> ~~parTupledN~~(fa: suspend () -> A, fb: suspend () -> B): Pair<A, B>
Runs fa, fb in parallel on ctx and combines their results into a Pairsuspend fun <A, B> ~~parTupledN~~(ctx: CoroutineContext = EmptyCoroutineContext, fa: suspend () -> A, fb: suspend () -> B): Pair<A, B>
Runs fa, fb, fc in parallel on Dispatchers.Default and combines their results into Triple.suspend fun <A, B, C> ~~parTupledN~~(fa: suspend () -> A, fb: suspend () -> B, fc: suspend () -> C): Triple<A, B, C>
Runs fa, fb, fc in parallel on ctx and combines their results using the provided function.suspend fun <A, B, C> ~~parTupledN~~(ctx: CoroutineContext = EmptyCoroutineContext, fa: suspend () -> A, fb: suspend () -> B, fc: suspend () -> C): Triple<A, B, C>
parZip Runs fa, fb in parallel on Dispatchers.Default and combines their results using the provided function.suspend fun <A, B, C> parZip(fa: suspend CoroutineScope.() -> A, fb: suspend CoroutineScope.() -> B, f: suspend CoroutineScope.(A, B) -> C): C
Runs fa, fb in parallel on ctx and combines their results using the provided function.suspend fun <A, B, C> parZip(ctx: CoroutineContext = EmptyCoroutineContext, fa: suspend CoroutineScope.() -> A, fb: suspend CoroutineScope.() -> B, f: suspend CoroutineScope.(A, B) -> C): C
Runs fa, fb, fc in parallel on Dispatchers.Default and combines their results using the provided function.suspend fun <A, B, C, D> parZip(fa: suspend CoroutineScope.() -> A, fb: suspend CoroutineScope.() -> B, fc: suspend CoroutineScope.() -> C, f: suspend CoroutineScope.(A, B, C) -> D): D
Runs fa, fb, fc in parallel on ctx and combines their results using the provided function.suspend fun <A, B, C, D> parZip(ctx: CoroutineContext = EmptyCoroutineContext, fa: suspend CoroutineScope.() -> A, fb: suspend CoroutineScope.() -> B, fc: suspend CoroutineScope.() -> C, f: suspend CoroutineScope.(A, B, C) -> D): D
Runs fa, fb, fc, fd in parallel on Dispatchers.Default and combines their results using the provided function.suspend fun <A, B, C, D, E> parZip(fa: suspend CoroutineScope.() -> A, fb: suspend CoroutineScope.() -> B, fc: suspend CoroutineScope.() -> C, fd: suspend CoroutineScope.() -> D, f: suspend CoroutineScope.(A, B, C, D) -> E): E
Runs fa, fb, fc, fd in parallel on ctx and combines their results using the provided function.suspend fun <A, B, C, D, E> parZip(ctx: CoroutineContext = EmptyCoroutineContext, fa: suspend CoroutineScope.() -> A, fb: suspend CoroutineScope.() -> B, fc: suspend CoroutineScope.() -> C, fd: suspend CoroutineScope.() -> D, f: suspend CoroutineScope.(A, B, C, D) -> E): E
Runs fa, fb, fc, fd, fe in parallel on Dispatchers.Default and combines their results using the provided function.suspend fun <A, B, C, D, E, F> parZip(fa: suspend CoroutineScope.() -> A, fb: suspend CoroutineScope.() -> B, fc: suspend CoroutineScope.() -> C, fd: suspend CoroutineScope.() -> D, fe: suspend CoroutineScope.() -> E, f: suspend CoroutineScope.(A, B, C, D, E) -> F): F
Runs fa, fb, fc, fd, fe in parallel on ctx and combines their results using the provided function.suspend fun <A, B, C, D, E, F> parZip(ctx: CoroutineContext = EmptyCoroutineContext, fa: suspend CoroutineScope.() -> A, fb: suspend CoroutineScope.() -> B, fc: suspend CoroutineScope.() -> C, fd: suspend CoroutineScope.() -> D, fe: suspend CoroutineScope.() -> E, f: suspend CoroutineScope.(A, B, C, D, E) -> F): F
Runs fa, fb, fc, fd, fe, ff in parallel on Dispatchers.Default and combines their results using the provided function.suspend fun <A, B, C, D, E, F, G> parZip(fa: suspend CoroutineScope.() -> A, fb: suspend CoroutineScope.() -> B, fc: suspend CoroutineScope.() -> C, fd: suspend CoroutineScope.() -> D, fe: suspend CoroutineScope.() -> E, ff: suspend CoroutineScope.() -> F, f: suspend CoroutineScope.(A, B, C, D, E, F) -> G): G
Runs fa, fb, fc, fd, fe, ff in parallel on ctx and combines their results using the provided function.suspend fun <A, B, C, D, E, F, G> parZip(ctx: CoroutineContext = EmptyCoroutineContext, fa: suspend CoroutineScope.() -> A, fb: suspend CoroutineScope.() -> B, fc: suspend CoroutineScope.() -> C, fd: suspend CoroutineScope.() -> D, fe: suspend CoroutineScope.() -> E, ff: suspend CoroutineScope.() -> F, f: suspend CoroutineScope.(A, B, C, D, E, F) -> G): G
Runs fa, fb, fc, fd, fe, ff, fg in parallel on Dispatchers.Default and combines their results using the provided function.suspend fun <A, B, C, D, E, F, G, H> parZip(fa: suspend CoroutineScope.() -> A, fb: suspend CoroutineScope.() -> B, fc: suspend CoroutineScope.() -> C, fd: suspend CoroutineScope.() -> D, fe: suspend CoroutineScope.() -> E, ff: suspend CoroutineScope.() -> F, fg: suspend CoroutineScope.() -> G, f: suspend CoroutineScope.(A, B, C, D, E, F, G) -> H): H
Runs fa, fb, fc, fd, fe, ff, fg in parallel on ctx and combines their results using the provided function.suspend fun <A, B, C, D, E, F, G, H> parZip(ctx: CoroutineContext = EmptyCoroutineContext, fa: suspend CoroutineScope.() -> A, fb: suspend CoroutineScope.() -> B, fc: suspend CoroutineScope.() -> C, fd: suspend CoroutineScope.() -> D, fe: suspend CoroutineScope.() -> E, ff: suspend CoroutineScope.() -> F, fg: suspend CoroutineScope.() -> G, f: suspend CoroutineScope.(A, B, C, D, E, F, G) -> H): H
Runs fa, fb, fc, fd, fe, ff, fg, fh in parallel on Dispatchers.Default and combines their results using the provided function.suspend fun <A, B, C, D, E, F, G, H, I> parZip(fa: suspend CoroutineScope.() -> A, fb: suspend CoroutineScope.() -> B, fc: suspend CoroutineScope.() -> C, fd: suspend CoroutineScope.() -> D, fe: suspend CoroutineScope.() -> E, ff: suspend CoroutineScope.() -> F, fg: suspend CoroutineScope.() -> G, fh: suspend CoroutineScope.() -> H, f: suspend CoroutineScope.(A, B, C, D, E, F, G, H) -> I): I
Runs fa, fb, fc, fd, fe, ff, fg, fh in parallel on ctx and combines their results using the provided function.suspend fun <A, B, C, D, E, F, G, H, I> parZip(ctx: CoroutineContext = EmptyCoroutineContext, fa: suspend CoroutineScope.() -> A, fb: suspend CoroutineScope.() -> B, fc: suspend CoroutineScope.() -> C, fd: suspend CoroutineScope.() -> D, fe: suspend CoroutineScope.() -> E, ff: suspend CoroutineScope.() -> F, fg: suspend CoroutineScope.() -> G, fh: suspend CoroutineScope.() -> H, f: suspend CoroutineScope.(A, B, C, D, E, F, G, H) -> I): I
prependTo infix fun <A> A.prependTo(q: IQueue<A>): IQueue<A>
raceN Races the participants fa, fb in parallel on the Dispatchers.Default. The winner of the race cancels the other participants. Cancelling the operation cancels all participants. An uncancellable participant will back-pressure the result of raceN.suspend fun <A, B> raceN(fa: suspend () -> A, fb: suspend () -> B): Either<A, B>
Races the participants fa, fb on the provided CoroutineContext. The winner of the race cancels the other participants. Cancelling the operation cancels all participants.suspend fun <A, B> raceN(ctx: CoroutineContext = EmptyCoroutineContext, fa: suspend () -> A, fb: suspend () -> B): Either<A, B>
Races the participants fa, fb & fc in parallel on the Dispatchers.Default. The winner of the race cancels the other participants. Cancelling the operation cancels all participants.suspend fun <A, B, C> raceN(fa: suspend () -> A, fb: suspend () -> B, fc: suspend () -> C): Race3<A, B, C>
Races the participants fa, fb & fc on the provided CoroutineContext. The winner of the race cancels the other participants. Cancelling the operation cancels all participants.suspend fun <A, B, C> raceN(ctx: CoroutineContext = EmptyCoroutineContext, fa: suspend () -> A, fb: suspend () -> B, fc: suspend () -> C): Race3<A, B, C>
racePair suspend fun <A, B> ~~racePair~~(fa: suspend () -> A, fb: suspend () -> B): RacePair<A, B>
Races two tasks concurrently within a new suspend fun. Race results in a winner and the other, yet to finish task running in a Fiber.suspend fun <A, B> ~~racePair~~(ctx: CoroutineContext, fa: suspend () -> A, fb: suspend () -> B): RacePair<A, B>
raceTriple suspend fun <A, B, C> ~~raceTriple~~(fa: suspend () -> A, fb: suspend () -> B, fc: suspend () -> C): RaceTriple<A, B, C>
Races three tasks concurrently within a new suspend fun. Race results in a winner and the others, yet to finish tasks running in Fiber.suspend fun <A, B, C> ~~raceTriple~~(ctx: CoroutineContext, fa: suspend () -> A, fb: suspend () -> B, fc: suspend () -> C): RaceTriple<A, B, C>
release Composes a release action to a Resource.use action creating a Resource.infix fun <A> Use<A>.release(release: suspend (A) -> Unit): Resource<A>
releaseCase Composes a releaseCase action to a Resource.use action creating a Resource.infix fun <A> Use<A>.releaseCase(release: suspend (A, ExitCase) -> Unit): Resource<A>
repeat Runs this effect once and, if it succeeded, decide using the provided policy if the effect should be repeated and if so, with how much delay. Returns the last output from the policy or raises an error if a repeat failed.suspend fun <A, B> ~~repeat~~(schedule: Schedule<A, B>, fa: suspend () -> A): B
repeatOrElse Runs this effect once and, if it succeeded, decide using the provided policy if the effect should be repeated and if so, with how much delay. Also offers a function to handle errors if they are encountered during repetition.suspend fun <A, B> ~~repeatOrElse~~(schedule: Schedule<A, B>, fa: suspend () -> A, orElse: suspend (Throwable, B?) -> B): B
repeatOrElseEither Runs this effect once and, if it succeeded, decide using the provided policy if the effect should be repeated and if so, with how much delay. Also offers a function to handle errors if they are encountered during repetition.suspend fun <A, B, C> ~~repeatOrElseEither~~(schedule: Schedule<A, B>, fa: suspend () -> A, orElse: suspend (Throwable, B?) -> C): Either<C, B>
resource Marks an acquire operation as the Resource.use step of a Resource.fun <A> resource(acquire: suspend () -> A): Use<A>
retry Runs an effect and, if it fails, decide using the provided policy if the effect should be retried and if so, with how much delay. Returns the result of the effect if if it was successful or re-raises the last error encountered when the schedule ends.suspend fun <A, B> ~~retry~~(schedule: Schedule<Throwable, B>, fa: suspend () -> A): A
retryOrElse Runs an effect and, if it fails, decide using the provided policy if the effect should be retried and if so, with how much delay. Also offers a function to handle errors if they are encountered during retrial.suspend fun <A, B> ~~retryOrElse~~(schedule: Schedule<Throwable, B>, fa: suspend () -> A, orElse: suspend (Throwable, B) -> A): A
retryOrElseEither Runs an effect and, if it fails, decide using the provided policy if the effect should be retried and if so, with how much delay. Also offers a function to handle errors if they are encountered during retrial.suspend fun <A, B, C> ~~retryOrElseEither~~(schedule: Schedule<Throwable, B>, fa: suspend () -> A, orElse: suspend (Throwable, B) -> C): Either<C, A>
sleep Sleeps for a given duration without blocking a thread.suspend fun ~~sleep~~(duration: Duration): Unit
timeOutOrNull Returns the result of fa within the specified duration or returns null.suspend fun <A> ~~timeOutOrNull~~(duration: Duration, fa: suspend () -> A): A?
uncancellable Runs f in an uncancellable manner. If f gets cancelled, it will back-pressure the cancelling operation until finished.suspend fun <A> ~~uncancellable~~(f: suspend () -> A): A
unit suspend fun unit(): Unit

Do you like Arrow?

Arrow Org
<