Hyperlinkv0.8.0-beta.28

TxSubscriptionRef

TxSubscriptionRef.changesStreamconsteffect/TxSubscriptionRef.ts:482
<A>(self: TxSubscriptionRef<A>): Stream.Stream<A, never, never>

Returns a Stream of all changes to the TxSubscriptionRef, starting with the current value followed by every subsequent update.

When to use

Use to consume TxSubscriptionRef committed changes as a Stream.

Example (Streaming changes)

import { Effect, Stream, TxSubscriptionRef } from "effect"

const program = Effect.gen(function*() {
  const ref = yield* TxSubscriptionRef.make(0)
  yield* TxSubscriptionRef.set(ref, 1)
  yield* TxSubscriptionRef.set(ref, 2)

  const values = yield* Stream.runCollect(
    TxSubscriptionRef.changesStream(ref).pipe(Stream.take(1))
  )
  console.log(values) // [2]
})
subscriptionschanges
export const changesStream = <A>(self: TxSubscriptionRef<A>): Stream.Stream<A, never, never> =>
  Stream.unwrap(
    Effect.map(
      changes(self),
      (sub) => Stream.fromEffectRepeat(Effect.tx(TxQueue.take(sub)))
    )
  )