Package: effect
Module: TxSubscriptionRef
Updates the value using a function and returns the new value. Publishes the new value to all subscribers.
When to use
Use to derive and publish a new TxSubscriptionRef value while returning
that new value.
Example (Updating and reading atomically)
import { Effect, TxSubscriptionRef } from "effect"
const program = Effect.gen(function*() {
const ref = yield* TxSubscriptionRef.make(3)
const result = yield* TxSubscriptionRef.updateAndGet(ref, (n) => n * 3)
console.log(result) // 9
})
See
update for updating without returning the new valuegetAndUpdate for returning the previous value insteadSignature
declare const updateAndGet: { <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