Skip to content

Instantly share code, notes, and snippets.

@dakk
Last active June 22, 2016 17:14
Show Gist options
  • Save dakk/dd892e81dd3db787dc229ee822421b9f to your computer and use it in GitHub Desktop.
Save dakk/dd892e81dd3db787dc229ee822421b9f to your computer and use it in GitHub Desktop.
Simple async for ocaml
open Printf;;
open Thread;;
let async f a fc =
let wrapper a = fc (f a) |> ignore in
Thread.create wrapper a;
Thread.yield ()
;;
(* Example *)
let test c = c*c;;
let ac c = Printf.printf "%d\n%!" c;;
let a c = Printf.printf "%d\n%!" c; 20;;
let b c = Printf.printf "%d\n%!" c; async a 21 ac |> ignore;;
Printf.printf "sleep\n";
async test 12 b;
Unix.sleep 2;
Printf.printf "sleeeep"
;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment