Package: effect
Module: TxSubscriptionRef
Gets the current value and sets a new value atomically. Publishes the new value to all subscribers.
When to use
Use to replace a TxSubscriptionRef value while returning the previous value
and publishing the update to subscribers.
Example (Getting and setting atomically)
import { Effect, TxSubscriptionRef } from "effect"
const program = Effect.gen(function*() {
const ref = yield* TxSubscriptionRef.make("a")
const old = yield* TxSubscriptionRef.getAndSet(ref, "b")
console.log(old) // "a"
console.log(yield* TxSubscriptionRef.get(ref)) // "b"
})
See
set for setting without returning the previous valuegetAndUpdate for deriving the new value from the previous valueSignature
declare const getAndSet: { <A>(value: A): (self: TxSubscriptionRef<A>) => Effect.Effect<A>; <A>(self: TxSubscriptionRef<A>, value: A): Effect.Effect<A>; }
Since v3.10.0