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:
1 parent
b6823867ff
commit
cf901ded5f
1 file changed
+8
-8
@@ -92,11 +92,6 @@ export type Clock = {
|
|||||||
sleep(ms: number): Promise<void>;
|
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
|
/** a cache's wiring: the webapp instance it asks on a miss, plus (private
|
||||||
* cache only) the public companion's id, recorded once published */
|
* cache only) the public companion's id, recorded once published */
|
||||||
@@ -122,9 +117,14 @@ abstract class PagedCache extends DurableObject<CacheEnv> {
|
|||||||
#pause?: Promise<void>;
|
#pause?: Promise<void>;
|
||||||
#clock: Clock;
|
#clock: Clock;
|
||||||
|
|
||||||
/** the runtime constructs DOs with (ctx, env); `clock` defaults to the
|
/** the runtime constructs DOs with (ctx, env), so the default — the
|
||||||
* live one, and a subclass can pass another */
|
* live clock, made here at the edge, nowhere in module scope — applies;
|
||||||
constructor(ctx: DurableObjectState, env: CacheEnv, clock: Clock = liveClock) {
|
* 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);
|
super(ctx, env);
|
||||||
this.#clock = clock;
|
this.#clock = clock;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user