flush method
Processes all pending tasks in the queue immediately.
This method will:
- Clear any existing timeout
- Take up to batchSize items from the queue
- Process them using the executeBatch function
- Remove the processed items from the queue
If the queue is empty, this method does nothing.
Implementation
Future<void> flush() async {
_clearTimer(); // Clear any existing timeout
// If the queue is empty, there's nothing to process
if (_queue.isEmpty) {
return;
}
// Create a batch from the queue and remove the processed tasks
List<T> batch = _queue.take(batchSize).toList();
if (batch.length >= batchSize) {
_queue = _queue.sublist(batchSize);
} else {
_queue = [];
}
// Execute the batch function with the current batch
await executeBatch(batch);
}