diff --git a/diigo-cache/src/cache.ts b/diigo-cache/src/cache.ts index 86eafee..e925d10 100644 --- a/diigo-cache/src/cache.ts +++ b/diigo-cache/src/cache.ts @@ -92,11 +92,6 @@ export type Clock = { sleep(ms: number): Promise; }; -/** 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 { #pause?: Promise; #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; }