Skip to main content Link Search Menu Expand Document (external link)

Deferred overview

Added in v2.0.0


Table of contents


constructors

make

Creates a new Deferred.

Signature

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

Added in v2.0.0

makeAs

Creates a new Deferred from the specified FiberId.

Signature

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

Added in v2.0.0

getters

await

Retrieves the value of the Deferred, suspending the fiber running the workflow until the result is available.

Signature

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

Added in v2.0.0

isDone

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

Signature

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

Added in v2.0.0

poll

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

Signature

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

Added in v2.0.0

models

Deferred (interface)

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

export interface Deferred<in out A, in out E = never> extends Effect.Effect<A, E>, Deferred.Variance<A, E> {
  /** @internal */
  readonly state: MutableRef.MutableRef<internal.State<A, E>>
  /** @internal */
  readonly blockingOn: FiberId.FiberId
  readonly [Unify.typeSymbol]?: unknown
  readonly [Unify.unifySymbol]?: DeferredUnify<this>
  readonly [Unify.ignoreSymbol]?: DeferredUnifyIgnore
}

Added in v2.0.0

DeferredUnify (interface)

Signature

export interface DeferredUnify<A extends { [Unify.typeSymbol]?: any }> extends Effect.EffectUnify<A> {
  Deferred?: () => Extract<A[Unify.typeSymbol], Deferred<any, any>>
}

Added in v3.8.0

DeferredUnifyIgnore (interface)

Signature

export interface DeferredUnifyIgnore extends Effect.EffectUnifyIgnore {
  Effect?: true
}

Added in v3.8.0

symbols

DeferredTypeId

Signature

export declare const DeferredTypeId: typeof DeferredTypeId

Added in v2.0.0

DeferredTypeId (type alias)

Signature

export type DeferredTypeId = typeof DeferredTypeId

Added in v2.0.0

unsafe

unsafeDone

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

Signature

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

Added in v2.0.0

unsafeMake

Unsafely creates a new Deferred from the specified FiberId.

Signature

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

Added in v2.0.0

utils

Deferred (namespace)

Added in v2.0.0

Variance (interface)

Signature

export interface Variance<in out A, in out E> {
  readonly [DeferredTypeId]: {
    readonly _A: Types.Invariant<A>
    readonly _E: Types.Invariant<E>
  }
}

Added in v2.0.0

complete

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

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

Added in v2.0.0

completeWith

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

Signature

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

Added in v2.0.0

die

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

Signature

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

Added in v2.0.0

dieSync

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

Signature

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

Added in v2.0.0

done

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

Signature

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

Added in v2.0.0

fail

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

Signature

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

Added in v2.0.0

failCause

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

Signature

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

Added in v2.0.0

failCauseSync

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

Signature

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

Added in v2.0.0

failSync

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

Signature

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

Added in v2.0.0

interrupt

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

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

Added in v2.0.0

interruptWith

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

Signature

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

Added in v2.0.0

succeed

Completes the Deferred with the specified value.

Signature

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

Added in v2.0.0

sync

Completes the Deferred with the specified lazily evaluated value.

Signature

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

Added in v2.0.0