aboutsummaryrefslogtreecommitdiff
path: root/lib/session.ml
diff options
context:
space:
mode:
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)