Utils: add Lwt_pipe.peek_all
This commit is contained in:
parent
2441ad6026
commit
bb90cc9dec
@ -136,6 +136,12 @@ let rec peek ({ closed ; queue ; _ } as q) =
|
|||||||
wait_push q >>= fun () ->
|
wait_push q >>= fun () ->
|
||||||
peek q
|
peek q
|
||||||
|
|
||||||
|
let peek_all { queue ; closed } =
|
||||||
|
if closed then
|
||||||
|
[]
|
||||||
|
else
|
||||||
|
List.rev (Queue.fold (fun acc (_, e) -> e :: acc) [] queue)
|
||||||
|
|
||||||
exception Empty
|
exception Empty
|
||||||
|
|
||||||
let pop_now_exn ({ closed ; queue ; empty ; current_size ; _ } as q) =
|
let pop_now_exn ({ closed ; queue ; empty ; current_size ; _ } as q) =
|
||||||
|
@ -42,6 +42,10 @@ 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. *)
|
||||||
|
|
||||||
|
val peek_all : 'a t -> 'a list
|
||||||
|
(** [peek_all q] returns the elements in the [q] (oldest first),
|
||||||
|
or [[]] if empty. *)
|
||||||
|
|
||||||
val values_available : 'a t -> unit Lwt.t
|
val values_available : 'a t -> unit Lwt.t
|
||||||
(** [values_available] is like [peek] but it ignores the value
|
(** [values_available] is like [peek] but it ignores the value
|
||||||
returned. *)
|
returned. *)
|
||||||
|
Loading…
Reference in New Issue
Block a user