Hyperlinkv0.8.0-beta.28

TxDeferred

TxDeferred.awaitconsteffect/TxDeferred.ts:134
<A, E>(self: TxDeferred<A, E>): Effect.Effect<A, E>

Reads the deferred value. Retries the transaction if the deferred has not been completed yet.

Example (Awaiting a deferred value)

import { Effect, TxDeferred } from "effect"

const program = Effect.gen(function*() {
  const deferred = yield* TxDeferred.make<number>()
  yield* TxDeferred.succeed(deferred, 42)
  const value = yield* TxDeferred.await(deferred)
  console.log(value) // 42
})
getters
const await_ = <A, E>(self: TxDeferred<A, E>): Effect.Effect<A, E> =>
  Effect.gen(function*() {
    const option = yield* TxRef.get(self.ref)
    if (O.isNone(option)) {
      return yield* Effect.txRetry
    }
    return Res.isSuccess(option.value)
      ? option.value.success
      : yield* Effect.fail(option.value.failure)
  }).pipe(Effect.tx)