Skip to content

Commit 4e1d73c

Browse files
committed
refactor: unify noAck check into single autoAck flag
1 parent ff4732e commit 4e1d73c

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

src/amqp-queue.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,11 @@ export class AMQPQueue {
8585
): Promise<AMQPSubscription | AMQPGeneratorSubscription> {
8686
if (typeof params === "function") [callback, params] = [params, undefined]
8787
const { prefetch, requeueOnNack = true, ...consumeParams } = params ?? {}
88-
// When auto-acking (callback or generator), force noAck: false so the server
89-
// tracks delivery tags. basicConsume defaults noAck to true, so we must be explicit.
90-
if (callback !== undefined && !consumeParams.noAck) {
91-
consumeParams.noAck = false
88+
// Force noAck: false when auto-acking so the server tracks delivery tags.
89+
// basicConsume defaults noAck to true, so we must be explicit.
90+
const autoAck = !consumeParams.noAck
91+
if (autoAck) consumeParams.noAck = false
92+
if (autoAck && callback !== undefined) {
9293
const userCallback = callback
9394
callback = async (msg: AMQPMessage) => {
9495
try {
@@ -99,10 +100,6 @@ export class AMQPQueue {
99100
}
100101
}
101102
}
102-
// Generator form: also force noAck: false for auto-ack unless caller opted out.
103-
if (callback === undefined && consumeParams.noAck !== true) {
104-
consumeParams.noAck = false
105-
}
106103
const def: ConsumerDefinition = {
107104
queueName: this.name,
108105
consumeParams,

0 commit comments

Comments
 (0)