Skip to content

Commit 57dc67b

Browse files
ImriKochWixclaude
andcommitted
feat(realtime): add managed-ticker API to RealtimeHandler type
Add protected tickIntervalMs + optional shouldTick() so handlers get types for the platform-managed tick loop (implemented in the deployed shim). Opting in means no more startLoop/stopLoop bookkeeping in the handler. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent d9732eb commit 57dc67b

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/realtime-handler.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ export abstract class RealtimeHandler<_State = unknown, Message = unknown> {
3434

3535
onStart(): void | Promise<void> {}
3636

37+
/**
38+
* Managed ticker (opt-in). Override {@link shouldTick} and the platform runs
39+
* {@link handleTick} on a timer of {@link tickIntervalMs} while it returns true,
40+
* and stops (letting the Durable Object hibernate — no compute cost) when it
41+
* returns false. The platform owns scheduling, rescheduling, self-heal, and
42+
* error-safety — you don't call {@link startLoop}/{@link stopLoop}.
43+
*
44+
* Re-evaluated after every connect/message/close and on every tick, so keep it
45+
* cheap and pure (no async, no side effects). Example: `return this.players >= 2`.
46+
*/
47+
protected tickIntervalMs = 100;
48+
protected shouldTick?(): boolean;
49+
3750
protected broadcast(_data: unknown): void {
3851
throw new Error("RealtimeHandler.broadcast() is only available inside a deployed handler");
3952
}

0 commit comments

Comments
 (0)