ocaml_monad_io / iO_Lwt.ml

type m +'a = Lwt.t 'a;

value return = Lwt.return;

value bind = Lwt.(=<<);

value bind_rev = Lwt.bind;

value error = Lwt.fail;

value catch = Lwt.catch;


(*************************)


value wrap_exn _place = error
;


value wrap1 place f = fun a ->
  catch (fun () -> f a)
  (wrap_exn place)
;

value wrap2 place f = fun a b ->
  catch (fun () -> f a b)
  (wrap_exn place)
;

value wrap4 place f = fun a b c d ->
  catch (fun () -> f a b c d)
  (wrap_exn place)
;

value read_into = wrap4 "read_into" Lwt_io.read_into;

value error = Lwt.fail;

type output_channel = Lwt_io.output_channel;
value stdout = Lwt_io.stdout;
value write = wrap2 "write" Lwt_io.write;

type input_channel = Lwt_io.input_channel;

value open_in = wrap1 "open_in" (
  fun fn ->
    Lwt_io.open_file
      ~mode:Lwt_io.input
      ~flags:[Unix.O_RDONLY]
     fn
  )
;

value close_in x = wrap1 "close_in" Lwt_io.close x;

value runIO x : [= `Ok of 'a | `Error of exn ] =
  try `Ok (Lwt_main.run x)
  with [e -> `Error e]
;

value with_file_in_bin filename func =
  Lwt_io.with_file ~mode:Lwt_io.input filename func
;

value with_file_out_bin filename func =
  Lwt_io.with_file ~mode:Lwt_io.output filename func
;

(********************************************************)

value stdin = Lwt_io.stdin;

value printf fmt = Printf.ksprintf (write stdout) fmt;

value flush = Lwt_io.flush;

value close_out = Lwt_io.close;


(********************************************************)

type server = Lwt_io.server;

value establish_server ?buffer_size ?backlog sa func =
  Lwt_io.establish_server ?buffer_size ?backlog sa func
;

value shutdown_server = Lwt_io.shutdown_server
;

value run_and_ignore_result = Lwt.ignore_result
;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.