Last active
June 22, 2016 17:14
-
-
Save dakk/dd892e81dd3db787dc229ee822421b9f to your computer and use it in GitHub Desktop.
Simple async for ocaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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