Skip to content

Commit

Permalink
remove unused from PromiseBag api
Browse files Browse the repository at this point in the history
  • Loading branch information
edchapman88 committed Nov 19, 2024
1 parent 6224613 commit b0f4f47
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
8 changes: 3 additions & 5 deletions lib/promiseBag.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ let count bag = List.length bag
(** Cons the new promise onto the list that represents the promise bag. *)
let insert bag promise = promise :: bag

(** Use [List.map]. *)
let map f bag = bag |> List.map f

(** Use [Lwt.all] directly. *)
let all bag = bag |> Lwt.all
let all bag =
let open Lwt.Infix in
bag |> Lwt.all >|= List.map Lwt.return

let filter_resolved bag =
(* [check_resolved resl pend ps] recursively matches on the head [p] of the list of promises [ps]. The state of [p] is checked and it is added to either the resolved ([resl]) or pending ([pend]) accumulator. [check_resolved] is then called on the tail of list. *)
Expand All @@ -25,4 +24,3 @@ let filter_resolved bag =
| Lwt.Sleep -> check_resolved resolved (p :: pending) ps)
in
check_resolved [] [] bag

7 changes: 2 additions & 5 deletions lib/promiseBag.mli
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,5 @@ val insert : 'a t -> 'a Lwt.t -> 'a t
val filter_resolved : 'a t -> 'a t * 'a t
(** [filter_resolved bag] filters the [bag] for all of the promises that are in a resolved state. A tuple of bags is returned, the first containing the promises that are in a resolved state, the second containing all of the other promises that are in a pending state. *)

val map : ('a Lwt.t -> 'b Lwt.t) -> 'a t -> 'b t
(** [map f bag] applies [f] to each of the promises in the [bag]. *)

val all : 'a t -> 'a list Lwt.t
(** [all bag] behaves like [Lwt.all]. The returned promise resolves once all of the promises in the bag have resolved. The returned promise resolves to a list of the values resolved from the promises in the bag. If at least one of the promises in the bag is rejected, the returned promise is rejected, and none of the fulfilled promises (if any) are available. *)
val all : 'a t -> 'a t Lwt.t
(** [all bag] behaves like [Lwt.all]. The returned promise resolves once all of the promises in the bag have resolved. The returned promise resolves to a bag of promises, each in a fulfilled state. If at least one of the promises in the bag is rejected, the returned promise is rejected, and none of the fulfilled promises (if any) are available. *)

0 comments on commit b0f4f47

Please sign in to comment.