diff options
author | Clombrong <cromblong@egregore.fun> | 2025-08-14 15:02:13 +0200 |
---|---|---|
committer | Clombrong <cromblong@egregore.fun> | 2025-08-14 15:02:13 +0200 |
commit | ed0065d2769a78c866e680697ebb70a6976708c6 (patch) | |
tree | 36ba84366be94123c5a8addff10ceb7fa11f5201 | |
parent | 00b2a40656dad43b1d48212e4b53f145b24ea3e8 (diff) |
feat(session): pass portal via state
-rw-r--r-- | lib/session.ml | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/lib/session.ml b/lib/session.ml index b874c23..94688bc 100644 --- a/lib/session.ml +++ b/lib/session.ml @@ -4,7 +4,8 @@ open Lwt_react type state = | Disconnected - | Connecting + | Opening_portal of string + | Connecting of Portal.t | Connected of Portal.t * Stream.features (** [create domain config] is a promise containing a signal representing the portal @@ -17,11 +18,8 @@ type state = a "ready" state. *) let create (domain : string) (config : Stream.config) : (state signal * (unit -> unit)) Lwt.t = let state, update = S.create Disconnected in - let connect () : unit Lwt.t = - let open Portal in + let connect (portal : Portal.t) : unit Lwt.t = let open Stream in - let* portal = connect domain - in let needs_restart = function | Feature.Mechanisms _ | STARTTLS -> true | _ -> false @@ -39,7 +37,11 @@ let create (domain : string) (config : Stream.config) : (state signal * (unit -> in update (Connected (portal, features)) in let+ () = S.map_s - (function | Connecting -> connect () - | _ -> Lwt.return_unit) + (function + | Opening_portal domain -> + let+ portal = Portal.connect domain + in update (Connecting portal) + | Connecting portal -> connect portal + | _ -> Lwt.return_unit) state >|= S.keep; - in state, (fun () -> update Connecting) + in state, fun () -> update (Opening_portal domain) |