Last active
August 29, 2015 14:07
-
-
Save maximvl/2f0797027528f5dcb9f0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
let lwt_call f = | |
let t1,w1 = Lwt.wait () in | |
Lwt.ignore_result | |
(let res = f () in | |
Lwt.wakeup w1 res; | |
Lwt.return_unit); | |
t1 | |
;; | |
let read_direction dir = | |
lwt_call (fun () -> | |
match Graphics.read_key () with | |
',' -> 0 | |
| 'e' -> 3 | |
| 'o' -> 6 | |
| 'a' -> 9 | |
| _ -> dir) | |
;; | |
let timeout_direction dir = | |
lwt_call (fun () -> | |
print_endline "before timeout"; | |
Lwt_unix.sleep delay ; | |
print_endline "after timeout"; | |
dir ) | |
;; | |
let get_direction dir = | |
let t1 = read_direction dir | |
and t2 = timeout_direction dir in | |
Lwt.choose [t1;t2] | |
;; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment