Hyperlinkv0.8.0-beta.28

TxRef

TxRef.makeconsteffect/TxRef.ts:99
<A>(initial: A): Effect.Effect<TxRef<A>, never, never>

Creates a new TxRef with the specified initial value.

When to use

Use to create a TxRef inside an Effect workflow.

Example (Creating transactional references)

import { Effect, TxRef } from "effect"

const program = Effect.gen(function*() {
  // Create a transactional reference with initial value
  const counter = yield* TxRef.make(0)
  const name = yield* TxRef.make("Alice")

  // Use in transactions
  yield* Effect.tx(Effect.gen(function*() {
    yield* TxRef.set(counter, 42)
    yield* TxRef.set(name, "Bob")
  }))

  console.log(yield* TxRef.get(counter)) // 42
  console.log(yield* TxRef.get(name)) // "Bob"
})
constructors
Source effect/TxRef.ts:991 lines
export const make = <A>(initial: A) => Effect.sync(() => makeUnsafe(initial))
Referenced by 24 symbols