MCPcopy Create free account
hub / github.com/effect-app/libs / modifyWithPermitWithEffect

Function modifyWithPermitWithEffect

packages/effect-app/src/Effect.ts:103–114  ·  view source on GitHub ↗
(ref: Ref.Ref<A>, semaphore: Semaphore)

Source from the content-addressed store, hash-verified

101 * Ref has atomic modify support if synchronous, for Effect we need a Semaphore.
102 */
103export function modifyWithPermitWithEffect<A>(ref: Ref.Ref<A>, semaphore: Semaphore) {
104 const withPermit = semaphore.withPermits(1)
105 return <R, E, A2>(mod: (a: A) => Effect.Effect<readonly [A2, A], E, R>) =>
106 withPermit(
107 Effect
108 .flatMap(Ref.get(ref), mod)
109 .pipe(
110 Effect.tap(([, _]) => Ref.set(ref, _)),
111 Effect.map(([_]) => _)
112 )
113 )
114}
115
116type ServiceA<T> = T extends Effect.Effect<infer S, any, any> ? S
117 : T extends Context.Service<any, infer S> ? S

Callers

nothing calls this directly

Calls 5

withPermitsMethod · 0.65
pipeMethod · 0.65
getMethod · 0.65
setMethod · 0.65
mapMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…