fixup! diigo-cache: the caches take their clock as a constructor argument

No module-level liveClock: the live clock is made in the default
argument expression, at the edge where the runtime constructs the DO,
so module scope holds no powerful object.

Generated-by: Claude Opus 5.5
This commit is contained in:
dckc committed 2026-10-07 04:35:39 -05:00
1 parent b6823867ff
commit cf901ded5f
1 file changed
+8 -8
+8 -8
View File
@@ -92,11 +92,6 @@ export type Clock = {
sleep(ms: number): Promise<void>;
};
/** the live clock: the one place this module touches time */
const liveClock: Clock = {
now: () => Date.now(),
sleep: (ms) => new Promise((r) => setTimeout(r, ms)),
};
/** a cache's wiring: the webapp instance it asks on a miss, plus (private
* cache only) the public companion's id, recorded once published */
@@ -122,9 +117,14 @@ abstract class PagedCache extends DurableObject<CacheEnv> {
#pause?: Promise<void>;
#clock: Clock;
/** the runtime constructs DOs with (ctx, env); `clock` defaults to the
* live one, and a subclass can pass another */
constructor(ctx: DurableObjectState, env: CacheEnv, clock: Clock = liveClock) {
/** the runtime constructs DOs with (ctx, env), so the default — the
* live clock, made here at the edge, nowhere in module scope — applies;
* a subclass (tests) can pass another */
constructor(
ctx: DurableObjectState,
env: CacheEnv,
clock: Clock = { now: () => Date.now(), sleep: (ms) => new Promise((r) => setTimeout(r, ms)) },
) {
super(ctx, env);
this.#clock = clock;
}