Skip to content

Commit 4acfa79

Browse files
committed
Forward on_idle_timeout to WebSocketLifecycleEventReceiver
Lori delivers idle timeout events to WebSocketServer, but all four connection states discarded them. This adds the final hop from the _Open state to user code, following the existing on_throttled/ on_unthrottled pattern. Closes #25
1 parent 2be80ad commit 4acfa79

4 files changed

Lines changed: 24 additions & 1 deletion

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## Forward on_idle_timeout to WebSocketLifecycleEventReceiver
2+
3+
`WebSocketLifecycleEventReceiver` now includes an `on_idle_timeout()` callback, fired when lori's idle timeout triggers on an open connection. This lets connection actors react to idle timeouts — for example, to implement heartbeat-based dead connection detection.
4+
5+
The callback has a default no-op implementation, so existing code is unaffected. Override it in your `WebSocketServerActor` to handle idle timeouts:
6+
7+
```pony
8+
fun ref on_idle_timeout() =>
9+
// Connection went idle — close it
10+
_ws.close()
11+
```

mare/_connection_state.pony

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ primitive _Open is _ConnectionState
8383
server._fire_on_unthrottled()
8484

8585
fun on_sent(server: WebSocketServer ref, token: lori.SendToken) => None
86-
fun on_idle_timeout(server: WebSocketServer ref) => None
86+
87+
fun on_idle_timeout(server: WebSocketServer ref) =>
88+
server._fire_on_idle_timeout()
8789

8890
fun send_text(server: WebSocketServer ref, data: String val) =>
8991
server._send_frame(_FrameEncoder.text(data))

mare/web_socket_lifecycle_event_receiver.pony

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,7 @@ trait WebSocketLifecycleEventReceiver
6565
fun ref on_unthrottled() =>
6666
"""Called when backpressure is released on the connection."""
6767
None
68+
69+
fun ref on_idle_timeout() =>
70+
"""Called when the connection's idle timeout fires."""
71+
None

mare/web_socket_server.pony

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,3 +353,9 @@ class WebSocketServer is lori.ServerLifecycleEventReceiver
353353
| let r: WebSocketLifecycleEventReceiver ref => r.on_unthrottled()
354354
| None => _Unreachable()
355355
end
356+
357+
fun ref _fire_on_idle_timeout() =>
358+
match \exhaustive\ _lifecycle_event_receiver
359+
| let r: WebSocketLifecycleEventReceiver ref => r.on_idle_timeout()
360+
| None => _Unreachable()
361+
end

0 commit comments

Comments
 (0)