Skip to content

Deferred

26 exports Added in v2.0.0 Source

Constructors

make

Added in v2.0.0 Source

Creates a new Deferred.

Signature

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

makeAs

Added in v2.0.0 Source

Creates a new Deferred from the specified FiberId.

Signature

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

Getters

isDone

Added in v2.0.0 Source

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>;

poll

Added in v2.0.0 Source

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

Added in v2.0.0 Source

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

Added in v3.8.0 Source

Signature

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

DeferredUnifyIgnore interface

Added in v3.8.0 Source

Signature

interface DeferredUnifyIgnore extends EffectUnifyIgnore {
  Effect?: true;
}

Other

Signature

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

Deferred

Added in v2.0.0 Source

Symbols

Signature

declare const DeferredTypeId: unique symbol;

DeferredTypeId type

Added in v2.0.0 Source

Signature

type DeferredTypeId = typeof DeferredTypeId;

Unsafe

unsafeDone

Added in v2.0.0 Source

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;

unsafeMake

Added in v2.0.0 Source

Unsafely creates a new Deferred from the specified FiberId.

Signature

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

Utils

complete

Added in v2.0.0 Source

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>;
};

completeWith

Added in v2.0.0 Source

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>;
};

die

Added in v2.0.0 Source

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>;
};

dieSync

Added in v2.0.0 Source

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>;
};

done

Added in v2.0.0 Source

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>;
};

fail

Added in v2.0.0 Source

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>;
};

failCause

Added in v2.0.0 Source

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>;
};

failSync

Added in v2.0.0 Source

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>;
};

interrupt

Added in v2.0.0 Source

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>;
};

succeed

Added in v2.0.0 Source

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>;
};

sync

Added in v2.0.0 Source

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>;
};