fix bounded queue: try_pop should drain a closed queue

This commit is contained in:
Simon Cruanes 2025-12-09 20:51:12 -05:00
parent 0eb27174f0
commit 374a67c97a
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4

View file

@ -47,11 +47,13 @@ end = struct
let try_pop (self : 'a t) : 'a BQ.pop_result =
UM.protect self.mutex @@ fun () ->
(* first, try to pop the queue. We want to drain it even if it's closed. *)
try `Item (Queue.pop self.q)
with Queue.Empty ->
if self.closed then
`Closed
else (
try `Item (Queue.pop self.q) with Queue.Empty -> `Empty
)
else
`Empty
let push_while_not_full ~high_watermark (self : 'a t) (xs : 'a list) :
push_res =