Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class GatewayPresence {
ws.onerror = () => void this.handleClose(4000).catch(() => {});
liveSocket = ws;
// Safety: if HELLO never arrives, the alarm resets the zombie socket.
await this.ctx.setAlarm(Date.now() + 30_000);
await this.ctx.storage.setAlarm(Date.now() + 30_000);
}

private killSocket(ws: WebSocket): void {
Expand All @@ -129,7 +129,7 @@ export class GatewayPresence {
const delay = session.reconnectBackoffMs;
session.reconnectBackoffMs = nextBackoff(delay);
await this.ctx.storage.put('session', session);
await this.ctx.setAlarm(Date.now() + delay);
await this.ctx.storage.setAlarm(Date.now() + delay);
}

private async sendHeartbeat(session: GatewaySession): Promise<void> {
Expand Down Expand Up @@ -193,7 +193,7 @@ export class GatewayPresence {
},
}));
}
await this.ctx.setAlarm(Date.now() + jitter(session.heartbeatIntervalMs));
await this.ctx.storage.setAlarm(Date.now() + jitter(session.heartbeatIntervalMs));
} else if (op === 11) {
session.awaitingAck = false;
await this.ctx.storage.put('session', session);
Expand Down
6 changes: 2 additions & 4 deletions src/workers-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ declare interface DurableObjectStorage {
get<T>(key: string): Promise<T | undefined>;
put(key: string, value: unknown): Promise<void>;
deleteAll(): Promise<void>;
setAlarm(time: number | Date): Promise<void>;
getAlarm(): Promise<number | null>;
}

declare interface DurableObjectState {
storage: DurableObjectStorage;
acceptWebSocket(ws: WebSocket): void;
getWebSockets(): WebSocket[];
setAlarm(time: number | Date): Promise<void>;
getAlarm(): Promise<number | null>;
}

declare interface DurableObjectId {
Expand Down