Hyperlinkv0.8.0-beta.28

TxSubscriptionRef

TxSubscriptionRef.makeconsteffect/TxSubscriptionRef.ts:118
<A>(value: A): Effect.Effect<TxSubscriptionRef<A>>

Creates a new TxSubscriptionRef with the specified initial value.

When to use

Use to create a TxSubscriptionRef that publishes every committed update to subscribers.

Example (Creating a transactional subscription reference)

import { Effect, TxSubscriptionRef } from "effect"

const program = Effect.gen(function*() {
  const ref = yield* TxSubscriptionRef.make(42)
  const value = yield* TxSubscriptionRef.get(ref)
  console.log(value) // 42
})
constructorschanges
export const make = <A>(value: A): Effect.Effect<TxSubscriptionRef<A>> =>
  Effect.gen(function*() {
    const ref = yield* TxRef.make(value)
    const pubsub = yield* TxPubSub.unbounded<A>()
    const self = Object.create(TxSubscriptionRefProto)
    self[TypeId] = TypeId
    self.ref = ref
    self.pubsub = pubsub
    return self
  }).pipe(Effect.tx)