Avoid hanging waiting for operations when buffer has none

This commit is contained in:
Antonio Scandurra 2022-12-23 12:26:48 +01:00
parent 75803d8dbb
commit 344d05045d

View File

@ -6255,16 +6255,19 @@ fn split_operations(
#[cfg(not(any(test, feature = "test-support")))] #[cfg(not(any(test, feature = "test-support")))]
const CHUNK_SIZE: usize = 100; const CHUNK_SIZE: usize = 100;
let mut done = false;
std::iter::from_fn(move || { std::iter::from_fn(move || {
if operations.is_empty() { if done {
return None; return None;
} }
Some( let operations = operations
operations .drain(..cmp::min(CHUNK_SIZE, operations.len()))
.drain(..cmp::min(CHUNK_SIZE, operations.len())) .collect::<Vec<_>>();
.collect(), if operations.is_empty() {
) done = true;
}
Some(operations)
}) })
} }