fix: do not emit empty batches

This commit is contained in:
Simon Cruanes 2022-07-06 19:55:06 -04:00
parent 16667a3fcf
commit 41e9962c08
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4

View file

@ -240,13 +240,12 @@ end = struct
let pop_if_ready ?(force = false) ~now (self : _ t) : _ list option =
let@ () = with_mutex_ self.lock in
if
(force && not (is_empty_ self))
|| is_full_ self || timeout_expired_ ~now self
if self.size > 0 && (force || is_full_ self || timeout_expired_ ~now self)
then (
let l = self.q in
self.q <- [];
self.size <- 0;
assert (l <> []);
Some l
) else
None