Hyperlinkv0.8.0-beta.28

SynchronizedRef

SynchronizedRef.modifyconsteffect/SynchronizedRef.ts:282
<A, B>(f: (a: A) => readonly [B, A]): (
  self: SynchronizedRef<A>
) => Effect.Effect<B>
<A, B>(
  self: SynchronizedRef<A>,
  f: (a: A) => readonly [B, A]
): Effect.Effect<B>

Computes a return value and a new ref value atomically, stores the new value, and returns the computed result.

When to use

Use to derive a separate result and the next stored SynchronizedRef value from the same current value in one serialized pure update.

export const modify: {
  <A, B>(f: (a: A) => readonly [B, A]): (self: SynchronizedRef<A>) => Effect.Effect<B>
  <A, B>(self: SynchronizedRef<A>, f: (a: A) => readonly [B, A]): Effect.Effect<B>
} = dual(
  2,
  <A, B>(self: SynchronizedRef<A>, f: (a: A) => readonly [B, A]): Effect.Effect<B> =>
    self.semaphore.withPermit(Ref.modify(self.backing, f))
)