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

Class RefImpl

packages/effect/src/internal/ref.ts:19–40  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17}
18
19class RefImpl<in out A> extends Effectable.Class<A> implements Ref.Ref<A> {
20 commit() {
21 return this.get
22 }
23 readonly [RefTypeId] = refVariance
24 readonly [Readable.TypeId]: Readable.TypeId = Readable.TypeId
25 constructor(readonly ref: MutableRef.MutableRef<A>) {
26 super()
27 this.get = core.sync(() => MutableRef.get(this.ref))
28 }
29 readonly get: Effect.Effect<A>
30 modify<B>(f: (a: A) => readonly [B, A]): Effect.Effect<B> {
31 return core.sync(() => {
32 const current = MutableRef.get(this.ref)
33 const [b, a] = f(current)
34 if ((current as unknown) !== (a as unknown)) {
35 MutableRef.set(a)(this.ref)
36 }
37 return b
38 })
39 }
40}
41
42/** @internal */
43export const unsafeMake = <A>(value: A): Ref.Ref<A> => new RefImpl(MutableRef.make(value))

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…