blob: 8bc7487ed9ae7a863a28e8823d50f322ff1d9311 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
open Lwt.Syntax
open Js_of_ocaml
open Flesh
(* 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 = Stream.start domain
in let* _stream = Lwt_stream.get stream
in let* _auth = Auth.send_auth_stanza (stream, push)
"test@example.com" "password"
Auth.PLAIN
in push (Some "<iq>wrong</iq>");
let+ _recv = Lwt_stream.get stream in
push None
|