Hyperlinkv0.8.0-beta.28

SubscriptionRef

SubscriptionRef.updateconsteffect/SubscriptionRef.ts:721
<A>(update: (a: A) => A): (
  self: SubscriptionRef<A>
) => Effect.Effect<void>
<A>(self: SubscriptionRef<A>, update: (a: A) => A): Effect.Effect<void>

Updates the value of the SubscriptionRef with the result of applying a function, notifying subscribers of the change.

Example (Updating a value)

import { Effect, SubscriptionRef } from "effect"

const program = Effect.gen(function*() {
  const ref = yield* SubscriptionRef.make(10)

  yield* SubscriptionRef.update(ref, (n) => n * 2)

  const value = yield* SubscriptionRef.get(ref)
  console.log(value)
})
updating
export const update: {
  <A>(update: (a: A) => A): (self: SubscriptionRef<A>) => Effect.Effect<void>
  <A>(self: SubscriptionRef<A>, update: (a: A) => A): Effect.Effect<void>
} = dual(
  2,
  <A>(self: SubscriptionRef<A>, update: (a: A) => A) =>
    self.semaphore.withPermit(Effect.sync(() => setUnsafe(self, update(self.value))))
)
Referenced by 1 symbols