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

Deferred.ts overview

Since v2.0.0


Exports Grouped by Category


constructors

make

Creates a new Deferred.

Signature

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

Source

Since v2.0.0

makeAs

Creates a new Deferred from the specified FiberId.

Signature

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

Source

Since v2.0.0

getters

await

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

Signature

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

Source

Since v2.0.0

isDone

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>

Source

Since v2.0.0

poll

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

Source

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

Source

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

Source

Since v3.8.0

DeferredUnifyIgnore (interface)

Signature

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

Source

Since v3.8.0

symbols

DeferredTypeId

Signature

declare const DeferredTypeId: unique symbol

Source

Since v2.0.0

DeferredTypeId (type alias)

Signature

type DeferredTypeId = typeof DeferredTypeId

Source

Since 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

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

Source

Since v2.0.0

unsafeMake

Unsafely creates a new Deferred from the specified FiberId.

Signature

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

Source

Since v2.0.0

utils

Deferred (namespace)

Source

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

Source

Since 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

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

Source

Since 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

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

Source

Since 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

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

Source

Since 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

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

Source

Since 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

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

Source

Since 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

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

Source

Since 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

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

Source

Since 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

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

Source

Since 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

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

Source

Since 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

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

Source

Since 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

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

Source

Since v2.0.0

succeed

Completes the Deferred with the specified value.

Signature

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

Source

Since v2.0.0

sync

Completes the Deferred with the specified lazily evaluated value.

Signature

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

Source

Since v2.0.0