Skip to content

Instantly share code, notes, and snippets.

@superherointj
Created March 12, 2020 15:10
Show Gist options
  • Save superherointj/eac826dac431719d1e2b08eb6443c8c5 to your computer and use it in GitHub Desktop.
Save superherointj/eac826dac431719d1e2b08eb6443c8c5 to your computer and use it in GitHub Desktop.
LWT demo - SYNC vs ASYNC printing
(executable
(name lwt_demo1)
(libraries lwt lwt.unix)
(preprocess (pps lwt_ppx))
(flags (:standard -warn-error -22))
)
(*
Is Printf.printft SYNC? But...
*)
let () = Printf.printf "=== This line is printed last. Why?\n";;
(* Awaits the user to type something and then prints it. *)
let () =
Lwt_main.run begin
let%lwt data = Lwt_io.(read_line stdin) in
let%lwt () = Lwt_io.printl data in
Lwt.return ()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment