zio.blocks.async
ZIO Blocks Async — a lightweight asynchronous effect type.
An Async[A] is a (possibly suspended) computation that eventually yields an A or fails with a Throwable. Create one with async.Async.succeed, async.Async.fail, async.Async.attempt, or async.Async.promise; a bare A is not itself an Async[A]. Transform and combine values with the extension methods (map, flatMap, catchAll, await, ...) brought into scope by importing this package.
==Quick start==
import zio.blocks.async._
// completes immediately with 42
val a: Async[Int] = Async.promise[Int](c => c.succeed(42))
// ops + block for the result
val n: Int = a.map(_ + 1).block
Attributes
Members list
Packages
Type members
Classlikes
Constructors for Async values.
Constructors for Async values.
An Async[A] is created with one of succeed, fail, attempt, or promise (a bare A is not itself an Async[A]). The transformation and combination operators (map, flatMap, catchAll, await, ...) become available as extension methods on Async[A] after importing zio.blocks.async._.
Attributes
- Source
- Async.scala
- Supertypes
- Self type
-
Async.type
Attributes
- Companion
- class
- Source
- AsyncSelector.scala
- Supertypes
- Self type
-
AsyncSelector.type
A repeatable, round-robin selector for independently pending computations.
A repeatable, round-robin selector for independently pending computations.
Eligibility means that a slot is armed (initially, or by replace) and its computation has completed. Among eligible slots selection scans cyclically from the slot after the previous winner. Consequently a continuously eligible slot wins within at most armedCount successful selections.
The selector registers one stable waker per armed slot, rather than a new loser waker per call to select. A winning slot is disarmed atomically and cannot win twice. shutdown is idempotent and does not finish until cleanup for every still-armed loser has finished.
Attributes
- Companion
- object
- Source
- AsyncSelector.scala
- Supertypes
This object was generated by sbt-buildinfo.
This object was generated by sbt-buildinfo.
Attributes
- Source
- BuildInfo.scala
- Supertypes
-
trait Singletontrait Producttrait Mirrortrait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
- Self type
-
BuildInfo.type
Companion for Cancelable, providing the no-op handle.
Companion for Cancelable, providing the no-op handle.
Attributes
- Companion
- trait
- Source
- Cancelable.scala
- Supertypes
- Self type
-
Cancelable.type
Handle returned by Async.start (via Async.Running) that stops a running Async.
Handle returned by Async.start (via Async.Running) that stops a running Async.
Calling cancel() is idempotent and synchronous. It prevents a terminal value from being published if cancellation linearizes before the run reaches completion, and it is a no-op once the run has completed.
When cancellation wins, the driver also signals Pollable.cancel on the active pending operation. A source that can abort an in-flight socket read, timer, or callback registration implements that hook; the default hook is a no-op. Cancellation does not wait for an already-running Pollable.poll invocation to return.
Extends java.lang.AutoCloseable so a Async.Running handle can be used as a managed resource (scala.util.Using, Java try-with-resources): close simply delegates to cancel(). cancel remains the canonical verb — it names the domain operation (stop an in-flight computation) and, unlike AutoCloseable.close, declares no checked exception.
Attributes
- Companion
- object
- Source
- Cancelable.scala
- Supertypes
- Known subtypes
-
class Running[A]class AsyncSelector[A]
The completion capability handed to an Async.promise block: complete the resulting Async by calling succeed (with a value) or fail (with a cause), typically from an I/O callback.
The completion capability handed to an Async.promise block: complete the resulting Async by calling succeed (with a value) or fail (with a cause), typically from an I/O callback.
Thread-safe and '''one-shot''': the first call to succeed or fail wins; all subsequent calls are silent no-ops, regardless of which thread they come from.
Attributes
- Source
- Completer.scala
- Supertypes
Failure outcome of an Async. Constructed via Async.fail (or by Completer.fail, or captured from thrown code by Async.attempt); recovered via the .catchAll / .mapError / .orElse extensions or surfaced as a thrown Throwable by .block.
Failure outcome of an Async. Constructed via Async.fail (or by Completer.fail, or captured from thrown code by Async.attempt); recovered via the .catchAll / .mapError / .orElse extensions or surfaced as a thrown Throwable by .block.
A failure is terminal: once an Async has failed, it stays failed with the same cause unless a handler such as .catchAll recovers it.
NOTE: errors thrown by user code inside .map(f) / .flatMap(f) are NOT captured — Async is eager, so a throw in f escapes through the call site before any later .catchAll runs. To convert thrown exceptions into a Failure, wrap the work in Async.attempt.
Attributes
- Source
- Failure.scala
- Supertypes
The implementation point for a custom suspended Async leaf (a timer, a socket read, a callback bridge, ...). A Pollable[A] is itself an Async[A], so it can be used wherever an Async[A] is expected.
The implementation point for a custom suspended Async leaf (a timer, a socket read, a callback bridge, ...). A Pollable[A] is itself an Async[A], so it can be used wherever an Async[A] is expected.
Implementors define poll: when asked for its value, a pollable either returns the completed result (a value, or a failed Async) or, if it is still pending, stashes the supplied java.lang.Runnable and returns a pending Async (typically itself). When the value later becomes available it must invoke onComplete.run() to ask the scheduler to poll again.
Attributes
- Source
- Pollable.scala
- Supertypes
- Known subtypes
Types
A possibly-suspended computation that will eventually yield an A (or fail with a Throwable). A async.Pollable may be used wherever an Async[A] is expected.
A possibly-suspended computation that will eventually yield an A (or fail with a Throwable). A async.Pollable may be used wherever an Async[A] is expected.
Async is a restricted monad: A must not itself be an Async (nor a async.Pollable). Compose effects with flatMap rather than nesting them as success values; Async[Async[A]] is unsupported.
Attributes
- Source
- package.scala
Value members
Inherited methods
Complete the surrounding Async.promise block with a failure.
Complete the surrounding Async.promise block with a failure.
Attributes
- Inherited from:
- AsyncSyntaxVersionSpecific (hidden)
- Source
- AsyncSyntaxVersionSpecific.scala
Complete the surrounding Async.promise block with value.
Complete the surrounding Async.promise block with value.
Attributes
- Inherited from:
- AsyncSyntaxVersionSpecific (hidden)
- Source
- AsyncSyntaxVersionSpecific.scala
Inverse of when: evaluate fa only when cond is false.
Inverse of when: evaluate fa only when cond is false.
Attributes
- Inherited from:
- AsyncSyntaxVersionSpecific (hidden)
- Source
- AsyncSyntaxVersionSpecific.scala
Conditionally evaluate fa. Returns fa.unit when cond is true, Async.succeed(()) otherwise. The unevaluated fa is by-name so it is not constructed when the condition is false.
Conditionally evaluate fa. Returns fa.unit when cond is true, Async.succeed(()) otherwise. The unevaluated fa is by-name so it is not constructed when the condition is false.
Attributes
- Inherited from:
- AsyncSyntaxVersionSpecific (hidden)
- Source
- AsyncSyntaxVersionSpecific.scala
Extensions
Inherited extensions
Convert fa into a java.util.concurrent.CompletableFuture that completes with the same value or error, for Java-shaped consumers.
Convert fa into a java.util.concurrent.CompletableFuture that completes with the same value or error, for Java-shaped consumers.
Attributes
- Inherited from:
- AsyncSyntaxPlatformSpecific (hidden)
- Source
- AsyncSyntaxPlatformSpecific.scala
Convert fa into a scala.concurrent.Future that completes with the same value or error. A not-yet-complete fa is driven on ec, so this returns immediately and the future completes when fa does.
Convert fa into a scala.concurrent.Future that completes with the same value or error. A not-yet-complete fa is driven on ec, so this returns immediately and the future completes when fa does.
Attributes
- Inherited from:
- AsyncSyntaxPlatformSpecific (hidden)
- Source
- AsyncSyntaxPlatformSpecific.scala
Sequence then return that's value (zipRight, ZIO's *>).
Sequence then return that's value (zipRight, ZIO's *>).
Attributes
- Inherited from:
- AsyncSyntaxVersionSpecific (hidden)
- Source
- AsyncSyntaxVersionSpecific.scala
Sequence then return fa's value (zipLeft, ZIO's <*).
Sequence then return fa's value (zipLeft, ZIO's <*).
Attributes
- Inherited from:
- AsyncSyntaxVersionSpecific (hidden)
- Source
- AsyncSyntaxVersionSpecific.scala
Replace the value with b. Equivalent to fa.map(_ => b).
Replace the value with b. Equivalent to fa.map(_ => b).
Attributes
- Inherited from:
- AsyncSyntaxVersionSpecific (hidden)
- Source
- AsyncSyntaxVersionSpecific.scala
Direct-style await: extract the value of fa without blocking, usable '''only''' directly inside an Async.async { ... } block. Using .await anywhere else is a compile error.
Direct-style await: extract the value of fa without blocking, usable '''only''' directly inside an Async.async { ... } block. Using .await anywhere else is a compile error.
Attributes
- Inherited from:
- AsyncSyntaxVersionSpecific (hidden)
- Source
- AsyncSyntaxVersionSpecific.scala
Drive fa to its value, blocking the calling thread until it is ready. A failure is re-thrown as its cause.
Drive fa to its value, blocking the calling thread until it is ready. A failure is re-thrown as its cause.
This is the unsafe escape hatch: ready values return immediately; a pending value blocks the (Loom-friendly) calling thread on the JVM, and on JS — which cannot block — throws. Inside an Async.async { ... } block use the direct-style await instead, which runs without blocking.
Attributes
- Inherited from:
- AsyncSyntaxVersionSpecific (hidden)
- Source
- AsyncSyntaxVersionSpecific.scala
Recover from a failure by applying f to its cause. A successful fa is returned unchanged (the handler is not invoked).
Recover from a failure by applying f to its cause. A successful fa is returned unchanged (the handler is not invoked).
Attributes
- Inherited from:
- AsyncSyntaxVersionSpecific (hidden)
- Source
- AsyncSyntaxVersionSpecific.scala
Convert any Failure into a Left; any value into a Right.
Convert any Failure into a Left; any value into a Right.
Attributes
- Inherited from:
- AsyncSyntaxVersionSpecific (hidden)
- Source
- AsyncSyntaxVersionSpecific.scala
Run finalizer after fa completes — success, failure, or suspension — and propagate the original outcome. A failure in finalizer is suppressed (the original outcome wins).
Run finalizer after fa completes — success, failure, or suspension — and propagate the original outcome. A failure in finalizer is suppressed (the original outcome wins).
Attributes
- Inherited from:
- AsyncSyntaxVersionSpecific (hidden)
- Source
- AsyncSyntaxVersionSpecific.scala
Sequence fa with f: when fa succeeds, continue with f applied to its value. A failure short-circuits and is propagated unchanged.
Sequence fa with f: when fa succeeds, continue with f applied to its value. A failure short-circuits and is propagated unchanged.
Attributes
- Inherited from:
- AsyncSyntaxVersionSpecific (hidden)
- Source
- AsyncSyntaxVersionSpecific.scala
Fold a possibly-failed Async into a guaranteed-success value by handling both branches. Equivalent to fa.map(onSuccess).catchAll(t => Async.succeed(onFailure(t))).
Fold a possibly-failed Async into a guaranteed-success value by handling both branches. Equivalent to fa.map(onSuccess).catchAll(t => Async.succeed(onFailure(t))).
Attributes
- Inherited from:
- AsyncSyntaxVersionSpecific (hidden)
- Source
- AsyncSyntaxVersionSpecific.scala
Transform the success value of fa with f. A failure short-circuits and is propagated unchanged.
Transform the success value of fa with f. A failure short-circuits and is propagated unchanged.
Attributes
- Inherited from:
- AsyncSyntaxVersionSpecific (hidden)
- Source
- AsyncSyntaxVersionSpecific.scala
Transform the cause of any Failure; values pass through.
Transform the cause of any Failure; values pass through.
Attributes
- Inherited from:
- AsyncSyntaxVersionSpecific (hidden)
- Source
- AsyncSyntaxVersionSpecific.scala
Run f for its effect when fa succeeds, then yield fa's original value. A failure in fa (or in f) is propagated.
Run f for its effect when fa succeeds, then yield fa's original value. A failure in fa (or in f) is propagated.
Attributes
- Inherited from:
- AsyncSyntaxVersionSpecific (hidden)
- Source
- AsyncSyntaxVersionSpecific.scala
Discard the value. Equivalent to fa.as(()).
Discard the value. Equivalent to fa.as(()).
Attributes
- Inherited from:
- AsyncSyntaxVersionSpecific (hidden)
- Source
- AsyncSyntaxVersionSpecific.scala
Sequentially combine fa with that, fusing the values via the combinators Tuples combiner: a zip b zip c flattens to Async[(A, B, C)] rather than Async[((A, B), C)]. Unit on either side is erased by the Tuples instances; tuple-on-tuple inputs are heterogeneously-concatenated.
Sequentially combine fa with that, fusing the values via the combinators Tuples combiner: a zip b zip c flattens to Async[(A, B, C)] rather than Async[((A, B), C)]. Unit on either side is erased by the Tuples instances; tuple-on-tuple inputs are heterogeneously-concatenated.
Attributes
- Inherited from:
- AsyncSyntaxVersionSpecific (hidden)
- Source
- AsyncSyntaxVersionSpecific.scala
Combine fa with that using f. The two are sequenced strictly left-to-right: fa is driven to a value first, and only then is that driven. A failure in fa short-circuits without driving that; a failure in that is surfaced only after fa has succeeded.
Combine fa with that using f. The two are sequenced strictly left-to-right: fa is driven to a value first, and only then is that driven. A failure in fa short-circuits without driving that; a failure in that is surfaced only after fa has succeeded.
Attributes
- Inherited from:
- AsyncSyntaxVersionSpecific (hidden)
- Source
- AsyncSyntaxVersionSpecific.scala
Fall back to that if fa fails, widening the two success types through the combinators Concat instance: on Scala 3 the result is the native union A | B (so Async[Int].orElse(Async[String]) is Async[Int | String]), rather than collapsing both sides to their least upper bound. that is by-name, so the fallback is built only on failure.
Fall back to that if fa fails, widening the two success types through the combinators Concat instance: on Scala 3 the result is the native union A | B (so Async[Int].orElse(Async[String]) is Async[Int | String]), rather than collapsing both sides to their least upper bound. that is by-name, so the fallback is built only on failure.
The common case is allocation-free: when Concat.isIdentityLike (always so for a union, and for same-type / sub-/supertype / shared-supertype derivations), both sides are already valid Out values, so we skip the per-value left/right projections (no map wrappers) and just recover with a cast — for a ready fa this collapses to a no-op. Only a disjoint Scala 2 Either widening (isIdentityLike == false) actually projects each side through c.left / c.right.
Attributes
- Inherited from:
- AsyncSyntaxVersionSpecific (hidden)
- Source
- AsyncSyntaxVersionSpecific.scala
Eagerly drive an already-built fa and return a Async.Running handle. Separate (non-inline) extension so it can reach the in-package internal.AsyncRunner driver directly — driving an existing Async is distinct from the companion Async.start(body), which evaluates a by-name body (Future.apply-style).
Eagerly drive an already-built fa and return a Async.Running handle. Separate (non-inline) extension so it can reach the in-package internal.AsyncRunner driver directly — driving an existing Async is distinct from the companion Async.start(body), which evaluates a by-name body (Future.apply-style).
Attributes
- Inherited from:
- AsyncSyntaxVersionSpecific (hidden)
- Source
- AsyncSyntaxVersionSpecific.scala
Flatten an Async[Async[A]] one level.
Flatten an Async[Async[A]] one level.
Attributes
- Inherited from:
- AsyncSyntaxVersionSpecific (hidden)
- Source
- AsyncSyntaxVersionSpecific.scala