Hyperlinkv0.8.0-beta.28

TxDeferred

TxDeferred.failconsteffect/TxDeferred.ts:289
<E>(error: E): <A>(self: TxDeferred<A, E>) => Effect.Effect<boolean>
<A, E>(self: TxDeferred<A, E>, error: E): Effect.Effect<boolean>

Completes the deferred with a failure. Returns true if this was the first completion, false if already completed.

When to use

Use to complete a TxDeferred with a typed failure value.

Example (Completing with a failure)

import { Effect, TxDeferred } from "effect"

const program = Effect.gen(function*() {
  const deferred = yield* TxDeferred.make<number, string>()
  const first = yield* TxDeferred.fail(deferred, "boom")
  console.log(first) // true
  const second = yield* TxDeferred.fail(deferred, "boom2")
  console.log(second) // false
})
mutations
export const fail: {
  <E>(error: E): <A>(self: TxDeferred<A, E>) => Effect.Effect<boolean>
  <A, E>(self: TxDeferred<A, E>, error: E): Effect.Effect<boolean>
} = dual(
  2,
  <A, E>(self: TxDeferred<A, E>, error: E): Effect.Effect<boolean> => done(self, Res.fail(error))
)