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

Class SynchronizedImpl

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

@internal

Source from the content-addressed store, hash-verified

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