diff options
author | Clombrong <cromblong@egregore.fun> | 2025-06-29 05:42:29 +0200 |
---|---|---|
committer | Clombrong <cromblong@egregore.fun> | 2025-06-29 05:42:29 +0200 |
commit | 04d805ab3cbcc28302c56e3429101b09ec952a52 (patch) | |
tree | 2b2cf388e5a6e14c5c260249df58e384aff55a2f /portal | |
parent | 1fa0e770fe4d6108fe85ca7b49fd0e0b1e545215 (diff) |
feat(portal_ws): send close stanza after pushing None
Diffstat (limited to 'portal')
-rw-r--r-- | portal/ws/portal.ml | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/portal/ws/portal.ml b/portal/ws/portal.ml index 8160e77..0d15e5a 100644 --- a/portal/ws/portal.ml +++ b/portal/ws/portal.ml @@ -138,9 +138,18 @@ let connect domain = WebSocket. *) let fragment_stream, fragment_push = Lwt_stream.create () in let stream = ws_stream |> lwt_stream |> strings_to_bytes |> parse_xml ~report |> signals - and push = function + in + let push = function | Some fs -> Markup.iter (fun f -> fragment_push (Some f)) fs - | None -> fragment_push None + | None -> begin + (* We need to send the [<close>] stanza in full to the WebSocket. *) + Markup.iter (fun f -> fragment_push (Some f)) close; + Lwt.async + (fun () -> + (* We drain completely the stream when closing, so the socket can close. *) + let+ () = Markup_lwt.drain stream + in fragment_push None) + end in (* Elements filters all elements based on the `Start_element. By simply making it return true every time, we get a stream of stream of elements, with each sub-stream |