Utils: add Lwt_pipe.pop_all_now

This commit is contained in:
Benjamin Canou 2017-11-22 18:29:51 +01:00 committed by Grégoire Henry
parent cfd5151279
commit f145c4b196
2 changed files with 13 additions and 6 deletions

View File

@ -162,14 +162,17 @@ let rec values_available q =
else else
Lwt.return_unit Lwt.return_unit
let pop_all q = let rec pop_all_loop q acc =
let rec loop acc =
match pop_now_exn q with match pop_now_exn q with
| exception Empty -> List.rev acc | exception Empty -> List.rev acc
| e -> loop (e :: acc) | e -> pop_all_loop q (e :: acc)
in
let pop_all q =
pop q >>= fun e -> pop q >>= fun e ->
Lwt.return (loop [e]) Lwt.return (pop_all_loop q [e])
let pop_all_now q =
pop_all_loop q []
let close q = let close q =
if not q.closed then begin if not q.closed then begin

View File

@ -34,6 +34,10 @@ val pop_all : 'a t -> 'a list Lwt.t
removes and returns all the element in [q] (in the order they removes and returns all the element in [q] (in the order they
were inserted). *) were inserted). *)
val pop_all_now : 'a t -> 'a list
(** [pop_all_now q] returns all the element in [q] (in the order they
were inserted), or [[]] if [q] is empty. *)
val peek : 'a t -> 'a Lwt.t val peek : 'a t -> 'a Lwt.t
(** [peek] is like [pop] except it does not removes the first (** [peek] is like [pop] except it does not removes the first
element. *) element. *)