Skip to content

Commit

Permalink
revert(message)!: remove nack delay parameter (#668)
Browse files Browse the repository at this point in the history
  • Loading branch information
callmehiphop authored Jul 1, 2019
1 parent ede5784 commit ca8fe65
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
18 changes: 4 additions & 14 deletions src/subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,25 +175,16 @@ export class Message {
}
/**
* Removes the message from our inventory and schedules it to be redelivered.
* If the delay parameter is unset, it will be redelivered immediately.
*
* @param {number} [delay=0] The desired time to wait before the
* redelivery occurs.
*
* @example
* subscription.on('message', message => {
* message.nack();
* });
*
* @example <caption>Specify a delay to redeliver the message</caption>
* subscription.on('message', message => {
* message.nack(60); // redeliver in 1 minute
* });
*/
nack(delay?: number): void {
nack(): void {
if (!this._handled) {
this._handled = true;
this._subscriber.nack(this, delay);
this._subscriber.nack(this);
}
}
}
Expand Down Expand Up @@ -352,12 +343,11 @@ export class Subscriber extends EventEmitter {
* it from our inventory.
*
* @param {Message} message The message.
* @param {number} [delay=0] Delay to wait before redelivery.
* @return {Promise}
* @private
*/
async nack(message: Message, delay = 0): Promise<void> {
await this.modAck(message, delay);
async nack(message: Message): Promise<void> {
await this.modAck(message, 0);
this._inventory.remove(message);
}
/**
Expand Down
8 changes: 3 additions & 5 deletions test/subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -709,22 +709,20 @@ describe('Subscriber', () => {

describe('nack', () => {
it('should nack the message', () => {
const fakeDelay = 10;
const stub = sandbox.stub(subscriber, 'modAck');

message.nack(fakeDelay);
message.nack();

const [msg, delay] = stub.lastCall.args;
assert.strictEqual(msg, message);
assert.strictEqual(delay, fakeDelay);
assert.strictEqual(delay, 0);
});

it('should not nack the message if its been handled', () => {
const delay = 10;
const stub = sandbox.stub(subscriber, 'modAck');

message.ack();
message.nack(delay);
message.nack();

assert.strictEqual(stub.callCount, 0);
});
Expand Down

0 comments on commit ca8fe65

Please sign in to comment.