submit method

void submit(
  1. T task
)

Adds a task to the queue for batch processing.

The task will be processed when either:

  • The number of queued tasks reaches batchSize
  • The timeout period elapses after this task is added (if this is the first task in the queue)

Implementation

void submit(T task) {
  _queue.add(task); // Add the task to the queue

  // If we've reached batch size, process the queue
  if (_queue.length >= batchSize) {
    flush();
  }
  // If this is the first task added after the queue was processed, start the timeout
  else if (_queue.length == 1) {
    _startTimer();
  }
}