<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 const make: <A>(initial: A) => anyCreates 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"
})
make = <function (type parameter) A in <A>(initial: A): anyA>(initial: Ainitial: function (type parameter) A in <A>(initial: A): anyA) => import EffectEffect.sync(() => const makeUnsafe: <A>(
initial: A
) => TxRef<A>
Creates a new TxRef synchronously with the specified initial value.
When to use
Use to construct a TxRef synchronously when it must be created outside an
Effect workflow.
Example (Creating transactional references unsafely)
import { TxRef } from "effect"
// Create a TxRef synchronously (unsafe - use make instead in Effect contexts)
const counter = TxRef.makeUnsafe(0)
const config = TxRef.makeUnsafe({ timeout: 5000, retries: 3 })
// These are now ready to use in transactions
console.log(counter.value) // 0
console.log(config.value) // { timeout: 5000, retries: 3 }
makeUnsafe(initial: Ainitial))Referenced by 24 symbols
TxChunk.emptyTxChunk.fromIterableTxChunk.makeTxDeferred.makeTxHashMap.emptyTxHashMap.fromIterableTxHashMap.makeTxHashSet.emptyTxHashSet.fromHashSetTxHashSet.fromIterableTxHashSet.makeTxPriorityQueue.emptyTxPriorityQueue.fromIterableTxPubSub.boundedTxPubSub.droppingTxPubSub.slidingTxPubSub.unboundedTxQueue.boundedTxQueue.droppingTxQueue.slidingTxQueue.unboundedTxReentrantLock.makeTxSemaphore.makeTxSubscriptionRef.make