Completer

zio.blocks.async.Completer
final class Completer[A] extends Pollable[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.

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
Graph
Supertypes
class Pollable[A]
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def fail(cause: Throwable): Unit

Complete with the failure cause. Idempotent — the first completion wins.

Complete with the failure cause. Idempotent — the first completion wins.

Attributes

Source
Completer.scala
def peek: encoding.Async[A]

A snapshot of this completer as an Async that does '''not''' register a onComplete: if it has already been completed, the resulting Async is already completed with that value or failure; otherwise it is the still-pending computation backed by this completer.

A snapshot of this completer as an Async that does '''not''' register a onComplete: if it has already been completed, the resulting Async is already completed with that value or failure; otherwise it is the still-pending computation backed by this completer.

Attributes

Source
Completer.scala
def poll(onComplete: Runnable): encoding.Async[A]

Attempt to produce this computation's value. Returns the completed result if it is ready; otherwise registers onComplete (to be invoked when the value becomes available) and returns a still-pending Async.

Attempt to produce this computation's value. Returns the completed result if it is ready; otherwise registers onComplete (to be invoked when the value becomes available) and returns a still-pending Async.

A still-pending result is either this pollable itself (the common case) or a '''replacement''' pollable that represents the rest of the computation; the caller must direct its next poll at whatever pollable was returned. The built-in drivers (block, start, the interop runners) and every combinator follow this, so a conforming poll may hand back a new pollable at any suspension.

Returning the same identity means the caller may wait for the registered callback. Returning a distinct identity is synchronous progress: the caller must poll that replacement without waiting. An identity change is not a readiness event, so a caller or wrapper must not synthesize onComplete for it. Real callbacks may be stale, reentrant, or duplicated and are therefore coalescible wake permits rather than proof that a particular generation has completed.

Polling is a '''one-shot driver protocol''': a driver should keep polling only while poll returns a still-pending Pollable, and must stop as soon as it returns a terminal result — a raw value or a failed Async. The built-in drivers (block, start, and the interop runners) all follow this, so they never poll a settled computation again.

Re-polling a Pollable after it has returned a terminal result is outside the contract and is '''not''' guaranteed to be a pure re-observation: a continuation may run again and diagnostic state may be repeated. Drive computations through the built-in runners unless you are implementing this protocol yourself, in which case honor the stop-at-terminal rule.

Attributes

Source
Completer.scala
def succeed(a: A): Unit

Complete successfully with a. Idempotent — the first completion wins.

Complete successfully with a. Idempotent — the first completion wins.

Attributes

Source
Completer.scala

Inherited methods

def cancel(): Unit

Signal cancellation of the currently pending operation. Implementations that own cancellable work override this with an idempotent, non-blocking signal; computations without such work inherit the no-op. A running driver invokes this only when cancellation wins against completion.

Signal cancellation of the currently pending operation. Implementations that own cancellable work override this with an idempotent, non-blocking signal; computations without such work inherit the no-op. A running driver invokes this only when cancellation wins against completion.

Attributes

Inherited from:
Pollable
Source
Pollable.scala