MCPcopy Create free account
hub / github.com/Effect-TS/effect / SynchronizedImpl

Class SynchronizedImpl

packages/effect/src/internal/effect/circular.ts:675–701  ·  view source on GitHub ↗

@internal

Source from the content-addressed store, hash-verified

673
674/** @internal */
675class SynchronizedImpl<in out A> extends Effectable.Class<A> implements Synchronized.SynchronizedRef<A> {
676 readonly [SynchronizedTypeId] = synchronizedVariance
677 readonly [internalRef.RefTypeId] = internalRef.refVariance
678 readonly [Readable.TypeId]: Readable.TypeId = Readable.TypeId
679 constructor(
680 readonly ref: Ref.Ref<A>,
681 readonly withLock: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
682 ) {
683 super()
684 this.get = internalRef.get(this.ref)
685 }
686 readonly get: Effect.Effect<A>
687 commit() {
688 return this.get
689 }
690 modify<B>(f: (a: A) => readonly [B, A]): Effect.Effect<B> {
691 return this.modifyEffect((a) => core.succeed(f(a)))
692 }
693 modifyEffect<B, E, R>(f: (a: A) => Effect.Effect<readonly [B, A], E, R>): Effect.Effect<B, E, R> {
694 return this.withLock(
695 pipe(
696 core.flatMap(internalRef.get(this.ref), f),
697 core.flatMap(([b, a]) => core.as(internalRef.set(this.ref, a), b))
698 )
699 )
700 }
701}
702
703/** @internal */
704export const makeSynchronized = <A>(value: A): Effect.Effect<Synchronized.SynchronizedRef<A>> =>

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected