Skip to content
Effect 4.0 is here. One ecosystem. Zero dependencies.

Deferred

26 exports Since v2.0.0 Source

Constructors

Since v2.0.0

Creates a new Deferred.

Signature

declare const make: <A, E = never>() => Effect.Effect<Deferred<A, E>>
Since v2.0.0

Creates a new Deferred from the specified FiberId.

Signature

declare const makeAs: <A, E = never>(fiberId: FiberId.FiberId) => Effect.Effect<Deferred<A, E>>

Getters

Since v2.0.0

Returns true if this Deferred has already been completed with a value or an error, false otherwise.

Signature

declare const isDone: <A, E>(self: Deferred<A, E>) => Effect.Effect<boolean>
Since v2.0.0

Returns a Some<Effect<A, E, R>> from the Deferred if this Deferred has already been completed, None otherwise.

Signature

declare const poll: <A, E>(self: Deferred<A, E>) => Effect.Effect<Option.Option<Effect.Effect<A, E>>>

Models

Deferred

interface
Since v2.0.0

A Deferred represents an asynchronous variable that can be set exactly once, with the ability for an arbitrary number of fibers to suspend (by calling Deferred.await) and automatically resume when the variable is set.

Deferred can be used for building primitive actions whose completions require the coordinated action of multiple fibers, and for building higher-level concurrent or asynchronous structures.

Signature

interface Deferred<in out A, in out E = never> extends Effect<A, E>, Variance<A, E> {
readonly [ignoreSymbol]?: DeferredUnifyIgnore;
readonly [typeSymbol]?: unknown;
readonly [unifySymbol]?: DeferredUnify<Deferred<A, E>>;
}

DeferredUnify

interface
Since v3.8.0

Signature

interface DeferredUnify<A extends {
[typeSymbol]?: any;
}> extends EffectUnify<A> {
Deferred?: () => Extract<A[typeof typeSymbol], Deferred<any, any>>;
}
Since v3.8.0

Signature

interface DeferredUnifyIgnore extends EffectUnifyIgnore {
Effect?: true;
}

Other

Signature

declare const await: <A, E>(self: Deferred<A, E>) => Effect.Effect<A, E>
Since v2.0.0

Symbols

Signature

declare const DeferredTypeId: unique symbol
Since v2.0.0

Signature

type DeferredTypeId = typeof DeferredTypeId

Unsafe

Unsafely exits the Deferred with the specified Exit value, which will be propagated to all fibers waiting on the value of the Deferred.

Signature

declare const unsafeDone: <A, E>(self: Deferred<A, E>, effect: Effect.Effect<A, E>) => void

Unsafely creates a new Deferred from the specified FiberId.

Signature

declare const unsafeMake: <A, E = never>(fiberId: FiberId.FiberId) => Deferred<A, E>

Utils

Since v2.0.0

Completes the deferred with the result of the specified effect. If the deferred has already been completed, the method will produce false.

Note that Deferred.completeWith will be much faster, so consider using that if you do not need to memoize the result of the specified effect.

Signature

declare const complete: {
<A, E>(effect: Effect<A, E>): (self: Deferred<A, E>) => Effect<boolean>;
<A, E>(self: Deferred<A, E>, effect: Effect<A, E>): Effect<boolean>;
}

Completes the deferred with the result of the specified effect. If the deferred has already been completed, the method will produce false.

Signature

declare const completeWith: {
<A, E>(effect: Effect<A, E>): (self: Deferred<A, E>) => Effect<boolean>;
<A, E>(self: Deferred<A, E>, effect: Effect<A, E>): Effect<boolean>;
}
Since v2.0.0

Kills the Deferred with the specified defect, which will be propagated to all fibers waiting on the value of the Deferred.

Signature

declare const die: {
(defect: unknown): <A, E>(self: Deferred<A, E>) => Effect<boolean>;
<A, E>(self: Deferred<A, E>, defect: unknown): Effect<boolean>;
}
Since v2.0.0

Kills the Deferred with the specified defect, which will be propagated to all fibers waiting on the value of the Deferred.

Signature

declare const dieSync: {
(evaluate: LazyArg<unknown>): <A, E>(self: Deferred<A, E>) => Effect<boolean>;
<A, E>(self: Deferred<A, E>, evaluate: LazyArg<unknown>): Effect<boolean>;
}
Since v2.0.0

Exits the Deferred with the specified Exit value, which will be propagated to all fibers waiting on the value of the Deferred.

Signature

declare const done: {
<A, E>(exit: Exit<A, E>): (self: Deferred<A, E>) => Effect<boolean>;
<A, E>(self: Deferred<A, E>, exit: Exit<A, E>): Effect<boolean>;
}
Since v2.0.0

Fails the Deferred with the specified error, which will be propagated to all fibers waiting on the value of the Deferred.

Signature

declare const fail: {
<E>(error: E): <A>(self: Deferred<A, E>) => Effect<boolean>;
<A, E>(self: Deferred<A, E>, error: E): Effect<boolean>;
}

Fails the Deferred with the specified Cause, which will be propagated to all fibers waiting on the value of the Deferred.

Signature

declare const failCause: {
<E>(cause: Cause<E>): <A>(self: Deferred<A, E>) => Effect<boolean>;
<A, E>(self: Deferred<A, E>, cause: Cause<E>): Effect<boolean>;
}

Fails the Deferred with the specified Cause, which will be propagated to all fibers waiting on the value of the Deferred.

Signature

declare const failCauseSync: {
<E>(evaluate: LazyArg<Cause<E>>): <A>(self: Deferred<A, E>) => Effect<boolean>;
<A, E>(self: Deferred<A, E>, evaluate: LazyArg<Cause<E>>): Effect<boolean>;
}
Since v2.0.0

Fails the Deferred with the specified error, which will be propagated to all fibers waiting on the value of the Deferred.

Signature

declare const failSync: {
<E>(evaluate: LazyArg<E>): <A>(self: Deferred<A, E>) => Effect<boolean>;
<A, E>(self: Deferred<A, E>, evaluate: LazyArg<E>): Effect<boolean>;
}

Completes the Deferred with interruption. This will interrupt all fibers waiting on the value of the Deferred with the FiberId of the fiber calling this method.

Signature

declare const interrupt: <A, E>(self: Deferred<A, E>) => Effect.Effect<boolean>

Completes the Deferred with interruption. This will interrupt all fibers waiting on the value of the Deferred with the specified FiberId.

Signature

declare const interruptWith: {
(fiberId: FiberId): <A, E>(self: Deferred<A, E>) => Effect<boolean>;
<A, E>(self: Deferred<A, E>, fiberId: FiberId): Effect<boolean>;
}
Since v2.0.0

Completes the Deferred with the specified value.

Signature

declare const succeed: {
<A>(value: A): <E>(self: Deferred<A, E>) => Effect<boolean>;
<A, E>(self: Deferred<A, E>, value: A): Effect<boolean>;
}
Since v2.0.0

Completes the Deferred with the specified lazily evaluated value.

Signature

declare const sync: {
<A>(evaluate: LazyArg<A>): <E>(self: Deferred<A, E>) => Effect<boolean>;
<A, E>(self: Deferred<A, E>, evaluate: LazyArg<A>): Effect<boolean>;
}