aboutsummaryrefslogtreecommitdiff
path: root/lib/session.ml
diff options
context:
space:
mode:
authorClombrong <cromblong@egregore.fun>2025-08-12 12:06:24 +0200
committerClombrong <cromblong@egregore.fun>2025-08-14 14:51:27 +0200
commit1b4de3ec44510b0e2a9f5a6c90a1cf1a3c2b889f (patch)
tree0f86bcf2a6ebd167c8802a35cf7430a9139f752a /lib/session.ml
parent74ea7cd05d59c1b3a13bc697aa7a5623cca2f119 (diff)
feat(session): use state management in connection handling
Diffstat (limited to 'lib/session.ml')
-rw-r--r--lib/session.ml11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/session.ml b/lib/session.ml
index 5b61346..7534433 100644
--- a/lib/session.ml
+++ b/lib/session.ml
@@ -1,5 +1,6 @@
open Lwt.Syntax
open Lwt.Infix
+open Lwt_react
type state =
| Disconnected
@@ -32,3 +33,13 @@ let connect (domain : string) (config : Stream.config) : (Portal.t * Stream.feat
| features -> Lwt.return features
in start domain portal >>= handle_features
in (portal, features)
+
+let create (domain : string) (config : Stream.config) : (state signal * (unit -> unit)) Lwt.t =
+ let state, update = S.create Disconnected in
+ let+ () = S.map_s
+ (function
+ | Connecting -> let+ portal, features = connect domain config
+ in update (Connected (portal, features))
+ | _ -> Lwt.return_unit)
+ state >|= S.keep;
+ in state, (fun () -> update Connecting)