| 17 | } |
| 18 | |
| 19 | class 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 */ |
| 43 | export const unsafeMake = <A>(value: A): Ref.Ref<A> => new RefImpl(MutableRef.make(value)) |
nothing calls this directly
no outgoing calls
no test coverage detected