diff --git a/src/chan.ml b/src/chan.ml index 348a5801..5ce82376 100644 --- a/src/chan.ml +++ b/src/chan.ml @@ -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] diff --git a/src/chan.mli b/src/chan.mli index c36ee91a..dd18af2d 100644 --- a/src/chan.mli +++ b/src/chan.mli @@ -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]