Created
January 27, 2022 12:28
-
-
Save Et7f3/3b4f09ddf5ac1eacf0f4a360d8154d32 to your computer and use it in GitHub Desktop.
proposal for https://github.com/ocsigen/lwt/issues/919
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
(* just some type to work in one file *) | |
module Lwt = struct | |
type 'a t = 'a ref | |
end | |
type process_in = int | |
type ('handler, 'return) onTimeout = | |
| Catch: float -> (exn -> process_in -> 'return Lwt.t, 'return) onTimeout | |
| Fail: float -> (process_in -> 'return Lwt.t, 'return) onTimeout | |
| NoTimeout: (process_in -> 'return Lwt.t, 'return) onTimeout (* for the default value *) | |
let with_process_in (type handler return) ?(timeout: (handler, return) onTimeout option) (f: handler): return Lwt.t = | |
let process_in = 13 in | |
match timeout with | |
Some (Catch t) -> | |
Printf.printf "Sleep %f\n" t; | |
f (Invalid_argument "timeout") process_in | |
| None -> assert false (* to be typed *) | |
| Some (Fail t) -> | |
Printf.printf "Sleep %f\n" t; | |
if true then | |
f process_in | |
else | |
raise (Invalid_argument "timeout") | |
| Some NoTimeout -> f process_in |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment