MCPcopy
hub / github.com/Effect-TS/effect / TSubscriptionRefImpl

Class TSubscriptionRefImpl

packages/effect/src/internal/stm/tSubscriptionRef.ts:111–153  ·  view source on GitHub ↗

@internal

Source from the content-addressed store, hash-verified

109
110/** @internal */
111class TSubscriptionRefImpl<in out A> implements TSubscriptionRef.TSubscriptionRef<A> {
112 readonly [TSubscriptionRefTypeId] = TSubscriptionRefVariance
113 readonly [TRef.TRefTypeId] = tRefVariance
114
115 constructor(
116 readonly ref: TRef.TRef<A>,
117 readonly pubsub: TPubSub.TPubSub<A>
118 ) {}
119
120 get todos() {
121 return this.ref.todos
122 }
123
124 get versioned() {
125 return this.ref.versioned
126 }
127
128 pipe() {
129 return pipeArguments(this, arguments)
130 }
131
132 get changes(): STM.STM<TQueue.TDequeue<A>> {
133 return STM.gen(this, function*() {
134 const first = yield* TQueue.unbounded<A>()
135 yield* TQueue.offer(first, yield* TRef.get(this.ref))
136 return new TDequeueMerge(first, yield* TPubSub.subscribe(this.pubsub))
137 })
138 }
139
140 modify<B>(f: (a: A) => readonly [B, A]): STM.STM<B> {
141 return pipe(
142 TRef.get(this.ref),
143 STM.map(f),
144 STM.flatMap(([b, a]) =>
145 pipe(
146 TRef.set(this.ref, a),
147 STM.as(b),
148 STM.zipLeft(TPubSub.publish(this.pubsub, a))
149 )
150 )
151 )
152 }
153}
154
155/** @internal */
156export const make = <A>(value: A): STM.STM<TSubscriptionRef.TSubscriptionRef<A>> =>

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…