Skip to content
This repository was archived by the owner on Mar 17, 2026. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: flush is broken when ordering enabled and multiple batches present
  • Loading branch information
kimjoar committed Mar 28, 2023
commit 269664b7c6312c3946127d357ae5d94f7ec77b8d
6 changes: 3 additions & 3 deletions src/publisher/message-queues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,12 @@ export class OrderedQueue extends MessageQueue {
/**
* Starts a timeout to publish any pending messages.
*/
beginNextPublish(): void {
beginNextPublish(callback?: PublishDone): void {
const maxMilliseconds = this.batchOptions.maxMilliseconds!;
const timeWaiting = Date.now() - this.currentBatch.created;
const delay = Math.max(0, maxMilliseconds - timeWaiting);

this.pending = setTimeout(() => this.publish(), delay);
this.pending = setTimeout(() => this.publish(callback), delay);
}
/**
* Creates a new {@link MessageBatch} instance.
Expand Down Expand Up @@ -361,7 +361,7 @@ export class OrderedQueue extends MessageQueue {
this.handlePublishFailure(err);
definedCallback(err);
} else if (this.batches.length) {
this.beginNextPublish();
this.beginNextPublish(callback);
} else {
this.emit('drain');
definedCallback(null);
Expand Down