in src/main/java/com/spotify/google/cloud/pubsub/client/Publisher.java [318:340]
private void scheduleSend(final int queueSize) {
// Bail if this topic is already enqueued for sending.
if (pending) {
return;
}
// Reached the batch size? Enqueue topic for sending immediately.
if (queueSize >= batchSize) {
enqueueSend();
return;
}
// Schedule this topic for later enqueuing, allowing more messages to gather into a larger batch.
if (scheduled.compareAndSet(false, true)) {
try {
scheduler.schedule(this::scheduledEnqueueSend, maxLatencyMs, MILLISECONDS);
schedulerQueueSize.incrementAndGet();
} catch (RejectedExecutionException ignore) {
// Race with a call to close(). Ignore.
}
}
}