dune/src/future.mli

83 lines
2.0 KiB
OCaml
Raw Normal View History

2016-11-03 16:44:09 +00:00
(** Simplified Async/Lwt like monad *)
open Import
2016-11-03 16:44:09 +00:00
type 'a t
val return : 'a -> 'a t
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
2016-12-02 13:54:32 +00:00
val (>>|) : 'a t -> ('a -> 'b) -> 'b t
val both : 'a t -> 'b t -> ('a * 'b) t
2016-11-03 16:44:09 +00:00
val all : 'a t list -> 'a list t
val all_unit : unit t list -> unit t
2016-12-07 15:55:47 +00:00
val with_exn_handler : (unit -> 'a) -> handler:(exn -> Printexc.raw_backtrace -> unit) -> 'a
(** How to handle sub-process failures *)
type ('a, 'b) failure_mode =
| Strict : ('a, 'a) failure_mode
(** Fail if the process exits with anything else than [0] *)
| Accept : int list -> ('a, ('a, int) result) failure_mode
(** Accept the following non-zero exit codes, and return [Error code] if the process
exists with one of these codes. *)
(** Where to redirect standard output *)
type std_output_to =
| Terminal
| File of string
| Opened_file of opened_file
and opened_file =
{ filename : string
; desc : opened_file_desc
; tail : bool
(** If [true], the descriptor is closed after starting the command *)
}
and opened_file_desc =
| Fd of Unix.file_descr
| Channel of out_channel
2016-12-02 13:54:32 +00:00
(** [run ?dir ?stdout_to prog args] spawns a sub-process and wait for its termination *)
val run
: ?dir:string
-> ?stdout_to:std_output_to
-> ?stderr_to:std_output_to
2016-12-02 13:54:32 +00:00
-> ?env:string array
-> (unit, 'a) failure_mode
2016-12-02 13:54:32 +00:00
-> string
-> string list
-> 'a t
2016-12-02 13:54:32 +00:00
(** Run a command and capture its output *)
val run_capture
: ?dir:string
-> ?env:string array
-> (string, 'a) failure_mode
2016-12-02 13:54:32 +00:00
-> string
-> string list
-> 'a t
2016-12-02 13:54:32 +00:00
val run_capture_line
: ?dir:string
-> ?env:string array
-> (string, 'a) failure_mode
2016-12-02 13:54:32 +00:00
-> string
-> string list
-> 'a t
2016-12-02 13:54:32 +00:00
val run_capture_lines
: ?dir:string
-> ?env:string array
-> (string list, 'a) failure_mode
2016-12-02 13:54:32 +00:00
-> string
-> string list
-> 'a t
2016-11-03 16:44:09 +00:00
module Scheduler : sig
val go : ?log:Log.t -> 'a t -> 'a
(** Executes [f] before exiting, after all pending commands have finished *)
val at_exit_after_waiting_for_commands : (unit -> unit) -> unit
2016-11-03 16:44:09 +00:00
end