add Chan.pop_await

This commit is contained in:
Simon Cruanes 2023-07-09 17:45:25 -04:00
parent 12df71c3ab
commit 68e744290b
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 18 additions and 0 deletions

View file

@ -182,3 +182,12 @@ let close (self : _ t) : unit =
do
Domain_.relax ()
done
[@@@ifge 5.0]
let pop_await self =
match try_pop self with
| Some x -> x
| None -> Fut.await @@ pop self
[@@@endif]

View file

@ -41,3 +41,12 @@ val pop_block_exn : 'a t -> 'a
val close : _ t -> unit
(** Close the channel. Further push and pop calls will fail.
This is idempotent. *)
[@@@ifge 5.0]
val pop_await : 'a t -> 'a
(** Like {!pop} but suspends the current thread until an element is
available. See {!Fut.await} for more details.
@since NEXT_RELEASE *)
[@@@endif]