effect-io-ai

Package: effect
Module: TxRef

TxRef.make

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

Signature

declare const make: <A>(initial: A) => Effect.Effect<TxRef<A>, never, never>

Source

Since v2.0.0