import { Effect, Semaphore } from "effect"; /** Serializes explicit refreshes while allowing background refreshes to coalesce. */ export function makeRefreshCoordinator() { const semaphore = Semaphore.makeUnsafe(1); return { run: (effect: Effect.Effect) => semaphore.withPermit(effect), runIfIdle: (effect: Effect.Effect) => semaphore.withPermitsIfAvailable(1)(effect).pipe(Effect.asVoid), }; }