Hyperlinkv0.8.0-beta.28

Deferred

Deferred.failCauseconsteffect/Deferred.ts:467
<E>(cause: Cause.Cause<E>): <A>(self: Deferred<A, E>) => Effect<boolean>
<A, E>(self: Deferred<A, E>, cause: Cause.Cause<E>): Effect<boolean>

Attempts to complete the Deferred with the specified Cause.

When to use

Use to complete a Deferred with a full failure cause.

Details

Fibers waiting on the Deferred observe that cause only if this call completes it. The returned effect succeeds with true when this call completed the Deferred, or false if it was already completed.

Example (Failing a Deferred with a Cause)

import { Cause, Deferred, Effect } from "effect"

const program = Effect.gen(function*() {
  const deferred = yield* Deferred.make<number, string>()
  const success = yield* Deferred.failCause(
    deferred,
    Cause.fail("Operation failed")
  )
  console.log(success) // true
})
completion
export const failCause: {
  <E>(cause: Cause.Cause<E>): <A>(self: Deferred<A, E>) => Effect<boolean>
  <A, E>(self: Deferred<A, E>, cause: Cause.Cause<E>): Effect<boolean>
} = dual(
  2,
  <A, E>(self: Deferred<A, E>, cause: Cause.Cause<E>): Effect<boolean> => done(self, core.exitFailCause(cause))
)
Referenced by 2 symbols