Hyperlinkv0.8.0-beta.28

TxSubscriptionRef

TxSubscriptionRef.setconsteffect/TxSubscriptionRef.ts:241
<A>(value: A): (self: TxSubscriptionRef<A>) => Effect.Effect<void>
<A>(self: TxSubscriptionRef<A>, value: A): Effect.Effect<void>

Sets the value of the TxSubscriptionRef and publishes the new value to all subscribers.

When to use

Use to replace the current TxSubscriptionRef value with a known value and publish it.

Example (Setting a new value)

import { Effect, TxSubscriptionRef } from "effect"

const program = Effect.gen(function*() {
  const ref = yield* TxSubscriptionRef.make(0)
  yield* TxSubscriptionRef.set(ref, 42)
  console.log(yield* TxSubscriptionRef.get(ref)) // 42
})
export const set: {
  <A>(value: A): (self: TxSubscriptionRef<A>) => Effect.Effect<void>
  <A>(self: TxSubscriptionRef<A>, value: A): Effect.Effect<void>
} = dual(
  2,
  <A>(self: TxSubscriptionRef<A>, value: A): Effect.Effect<void> => modify(self, () => [void 0, value])
)