mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
a few utils in CCFuture
This commit is contained in:
parent
feec3bf46f
commit
bcdb1434e5
2 changed files with 30 additions and 8 deletions
|
|
@ -373,9 +373,17 @@ let slurp i_chan =
|
|||
)
|
||||
in next ()
|
||||
|
||||
let read_chan ic = make1 slurp ic
|
||||
|
||||
type subprocess_res = <
|
||||
errcode : int;
|
||||
stdout : Bytes.t;
|
||||
stderr : Bytes.t;
|
||||
>
|
||||
|
||||
(** Spawn a sub-process with the given command [cmd] (and possibly input);
|
||||
returns a future containing (returncode, stdout, stderr) *)
|
||||
let spawn_process ?(stdin="") ~cmd () =
|
||||
let spawn_process ?(stdin="") cmd : subprocess_res t =
|
||||
make
|
||||
(fun () ->
|
||||
(* spawn subprocess *)
|
||||
|
|
@ -394,7 +402,11 @@ let spawn_process ?(stdin="") ~cmd () =
|
|||
| Unix.WEXITED i -> i
|
||||
| Unix.WSIGNALED i -> i
|
||||
| Unix.WSTOPPED i -> i in
|
||||
(returncode, out', err')
|
||||
object
|
||||
method errcode = returncode
|
||||
method stdout = out'
|
||||
method stderr = err'
|
||||
end
|
||||
)
|
||||
|
||||
let sleep time = make (fun () -> Thread.delay time)
|
||||
|
|
|
|||
|
|
@ -94,13 +94,23 @@ val map : ('a -> 'b) -> 'a t -> 'b t
|
|||
|
||||
(** {2 Helpers} *)
|
||||
|
||||
val spawn_process : ?stdin:string -> cmd:string -> unit ->
|
||||
(int * string * string) t
|
||||
(** Spawn a sub-process with the given command [cmd] (and possibly input);
|
||||
returns a future containing (returncode, stdout, stderr) *)
|
||||
val read_chan : in_channel -> Bytes.t t
|
||||
(** Read the whole channel *)
|
||||
|
||||
type subprocess_res = <
|
||||
errcode : int;
|
||||
stdout : Bytes.t;
|
||||
stderr : Bytes.t;
|
||||
>
|
||||
|
||||
val spawn_process : ?stdin:string -> string -> subprocess_res t
|
||||
(** Spawn a sub-process with the given command (and possibly input);
|
||||
returns a future containing [(returncode, stdout, stderr)] *)
|
||||
|
||||
val sleep : float -> unit t
|
||||
(** Future that returns with success in the given amount of seconds *)
|
||||
(** Future that returns with success in the given amount of seconds. Blocks
|
||||
the thread! If you need to wait on many events, consider
|
||||
using {!Timer} *)
|
||||
|
||||
(** {2 Event timer} *)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue