Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify documentation of Lwt_stream.get_available #988

Open
iguerNL opened this issue Apr 20, 2023 · 0 comments
Open

Clarify documentation of Lwt_stream.get_available #988

iguerNL opened this issue Apr 20, 2023 · 0 comments

Comments

@iguerNL
Copy link

iguerNL commented Apr 20, 2023

The current documentation is as follows:

val get : 'a t -> 'a option Lwt.t
(** [get st] removes and returns the first element of the stream, if
    any. *)
val get_available : 'a t -> 'a list
(** [get_available st] returns all available elements of [l] without
    blocking. *)

One may think that get_available doesn't remove the elements, but it seems that it actually does (assuming removal is done by consume):

let rec get_available_rec node acc s =
  if node == !(s.last) then
    let thread = feed s in
    match Lwt.state thread with
    | Lwt.Return _ ->
      get_available_rec node acc s
    | Lwt.Fail exn ->
      raise exn
    | Lwt.Sleep ->
      List.rev acc
  else
    match node.data with
    | Some x ->
      consume s node;
      get_available_rec node.next (x :: acc) s
    | None ->
      List.rev acc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant