/** * Ref has atomic modify support if synchronous, for Effect we need a Semaphore. * @tsplus fluent effect/io/Ref modifyWithEffect */ export function modifyWithPermitWithEffect(ref: Ref, semaphore: Semaphore) { const withPermit = semaphore.withPermits(1) return (mod: (a: A) => Effect) => withPermit( ref.get .flatMap(mod) .tap(([, _]) => ref.set(_)) .map(([_]) => _) ) }