Skip to content

Instantly share code, notes, and snippets.

@rand00
Created October 26, 2018 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rand00/16e6e09fb8f779b4c35d4b6f8acb36cd to your computer and use it in GitHub Desktop.
Save rand00/16e6e09fb8f779b4c35d4b6f8acb36cd to your computer and use it in GitHub Desktop.
Structured concurrency semantics?
(*Example from http://libdill.org/ rewritten in Lwt*)
open Lwt
let rec worker s =
Lwt_io.printl s >>= fun () ->
Lwt_unix.sleep @@ Random.float 0.5 >>= fun () ->
worker s
let main =
let _ = worker "Hello!" in
let _ = worker "World!" in
Lwt_unix.sleep 5.
let _ =
Random.self_init ();
Lwt_main.run main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment