(ref: Ref.Ref<A>, semaphore: Semaphore)
| 101 | * Ref has atomic modify support if synchronous, for Effect we need a Semaphore. |
| 102 | */ |
| 103 | export 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 | |
| 116 | type ServiceA<T> = T extends Effect.Effect<infer S, any, any> ? S |
| 117 | : T extends Context.Service<any, infer S> ? S |
nothing calls this directly
no test coverage detected
searching dependent graphs…