From 1b4de3ec44510b0e2a9f5a6c90a1cf1a3c2b889f Mon Sep 17 00:00:00 2001 From: Clombrong Date: Tue, 12 Aug 2025 12:06:24 +0200 Subject: feat(session): use state management in connection handling --- test/hello.ml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/hello.ml b/test/hello.ml index dd06554..f4661c3 100644 --- a/test/hello.ml +++ b/test/hello.ml @@ -2,6 +2,7 @@ open! Lwt.Syntax open! Lwt.Infix open! Flesh open! Session +open! Lwt_react let main = let config : Stream.config = { @@ -14,14 +15,15 @@ let main = other = []; } in - let state, update = Lwt_react.S.create Disconnected in - Lwt_react.S.map (function - | Disconnected -> print_endline "Disconnected" - | Connecting -> print_endline "Connecting" - | Connected (portal, _) -> portal.push None) - state |> ignore; - try%lwt connect config.sasl.jid.domainpart config >|= - (fun (portal, state) -> update (Connected (portal, state))) + let waiter, wakener = Lwt.wait () in + try%lwt let* state, connect = create config.sasl.jid.domainpart config in + S.map (function + | Connected (portal, _) -> portal.push None; + Lwt.wakeup wakener () + | _ -> ()) + state |> S.keep; + connect (); + waiter with exn -> begin (* I suspect JavaScript's [wrap_callback] swallows the Exceptions thrown by -- cgit v1.2.3