Utils: add Lwt_pipe.pop_all
.
This commit is contained in:
parent
1a10504959
commit
f3abee1fdf
@ -161,6 +161,15 @@ let rec values_available q =
|
|||||||
else
|
else
|
||||||
Lwt.return_unit
|
Lwt.return_unit
|
||||||
|
|
||||||
|
let pop_all q =
|
||||||
|
let rec loop acc =
|
||||||
|
match pop_now_exn q with
|
||||||
|
| exception Empty -> List.rev acc
|
||||||
|
| e -> loop (e :: acc)
|
||||||
|
in
|
||||||
|
pop q >>= fun e ->
|
||||||
|
Lwt.return (loop [e])
|
||||||
|
|
||||||
let close q =
|
let close q =
|
||||||
if not q.closed then begin
|
if not q.closed then begin
|
||||||
q.closed <- true ;
|
q.closed <- true ;
|
||||||
|
@ -27,6 +27,11 @@ val pop : 'a t -> 'a Lwt.t
|
|||||||
(** [pop q] is a thread that blocks while [q] is empty, then
|
(** [pop q] is a thread that blocks while [q] is empty, then
|
||||||
removes and returns the first element in [q]. *)
|
removes and returns the first element in [q]. *)
|
||||||
|
|
||||||
|
val pop_all : 'a t -> 'a list Lwt.t
|
||||||
|
(** [pop_all q] is a thread that blocks while [q] is empty, then
|
||||||
|
removes and returns all the element in [q] (in the order they
|
||||||
|
were inserted). *)
|
||||||
|
|
||||||
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. *)
|
||||||
|
Loading…
Reference in New Issue
Block a user