Package: effect
Module: TxSubscriptionRef
Gets the current value and updates it using a function atomically. Publishes the new value to all subscribers.
When to use
Use to derive and publish a new TxSubscriptionRef value while returning the
previous value.
Example (Getting and updating atomically)
import { Effect, TxSubscriptionRef } from "effect"
const program = Effect.gen(function*() {
const ref = yield* TxSubscriptionRef.make(1)
const old = yield* TxSubscriptionRef.getAndUpdate(ref, (n) => n + 10)
console.log(old) // 1
console.log(yield* TxSubscriptionRef.get(ref)) // 11
})
See
update for updating without returning the previous valueupdateAndGet for returning the new value insteadSignature
declare const getAndUpdate: { <A>(f: (current: A) => A): (self: TxSubscriptionRef<A>) => Effect.Effect<A>; <A>(self: TxSubscriptionRef<A>, f: (current: A) => A): Effect.Effect<A>; }
Since v3.10.0