diff options
author | Clombrong <clombrong@egregore.fun> | 2025-05-30 10:55:32 +0200 |
---|---|---|
committer | Clombrong <cromblong@egregore.fun> | 2025-05-30 10:55:32 +0200 |
commit | 591038ba4f718007cacdf7a4f58b3c375fa2ee97 (patch) | |
tree | 5ef6770eb5ba8ddcd956e8e3a86dbbe49c898384 /test/js/websockets_hello.ml | |
parent | 91e3de96fd83cfda68b3a842702f1a70cc06768d (diff) |
test(js): move portal tests to global tests
Diffstat (limited to 'test/js/websockets_hello.ml')
-rw-r--r-- | test/js/websockets_hello.ml | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/js/websockets_hello.ml b/test/js/websockets_hello.ml new file mode 100644 index 0000000..5705dc9 --- /dev/null +++ b/test/js/websockets_hello.ml @@ -0,0 +1,28 @@ +open Lwt.Syntax +open Js_of_ocaml + +(* https://stackoverflow.com/questions/34929382/what-are-the-differences-between-lwt-async-and-lwt-main-run-on-ocaml-node-js *) +let rec run t = + let next_tick (_callback : unit -> unit) = + Js.Unsafe.(fun_call + (js_expr "process.nextTick") + [| inject (Js.wrap_callback _callback) |]) + in Lwt.wakeup_paused (); + match Lwt.poll t with + | Some x -> x + | None -> + if Lwt.paused_count () > 0 + then next_tick (fun () -> run t) + else () + +let () = + run @@ + let domain = "egregore.fun" in + let* stream, push = + Portal.connect domain in + push (Some (Portal.stanza_open domain)); + push (Some Portal.stanza_close); + Lwt_stream.iter + (fun stanza -> + print_endline (">>> " ^ stanza)) + stream |