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