You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(models): use Flock.effect, makeRuntime, cachedInvalidateWithTTL
Three review findings + a real bug:
1. Replace 'Effect.promise(() => Flock.withLock(... runPromise(fetchApi) ...))'
with 'Effect.scoped(Effect.gen { Flock.effect(lockKey); fetchAndWrite })'.
Flock.effect is the existing scoped acquire/release; the runPromise
re-entry inside the Promise lock body was dropping the parent fiber's
tracing span, scope, and interruption.
2. Replace hand-rolled 'ManagedRuntime.make(defaultLayer, { memoMap })' with
the existing 'makeRuntime(Service, defaultLayer)' helper from
src/effect/run-service.ts. Same pattern as bus, sync, instance-store, etc.
3. Use 'Effect.cachedInvalidateWithTTL(populate, Duration.infinity)' for
single-flight cache + manual invalidation. Concurrent first-callers now
share one populate; refresh() invalidates so the next get() re-populates.
4. Restore eager initial refresh — Schedule.fixed waits the duration before
the first run, which would have lost the original 'void refresh()' on
module load. Now: refresh().pipe(Effect.andThen(refresh().repeat(...))).
5. Simplify fresh() mtime check — fs.stat's info.mtime is always Option<Date>;
dropped the dead Option.isOption guard.
6. Drop unnecessary Effect.fnUntraced on loadFromDisk/loadSnapshot (these
are values, not traced effects). Replaced loadSnapshot's manual try/catch
wrapper with Effect.tryPromise + Effect.catch.
7. Effect.orDie on populate — Service interface declares get returns
Effect<Record<string, Provider>> (E = never); failures from HttpClient,
FileSystem, JSON.parse must die rather than silently leak.
Smoke + provider tests pass.
0 commit comments