Skip to content

Commit

Permalink
feat(adapter/amqp): not execute body of disconnect method when state …
Browse files Browse the repository at this point in the history
…is not connected
  • Loading branch information
CheerlessCloud committed Oct 4, 2018
1 parent 6e4d6e0 commit f0d46a1
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/AMQPAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,24 +256,29 @@ class AMQPAdapter {
}

async disconnect({ gracefulStopTimeout = 10000 }: { gracefulStopTimeout?: number } = {}) {
if (!['connecting', 'connected', 'blocked'].includes(this._state)) {
return;
}

this._state = 'disconnecting';

// @todo in wait end time reject with requeue all messages or unsubscribe
// but how we can ack is this situation?
if (gracefulStopTimeout > 0) {
try {
await this._waitEndHandlers(gracefulStopTimeout);
} catch (err) {
this._errorHandler(
EError.wrap(err, {
gracefulStopTimeout,
subMessage: 'Error at graceful disconnect',
}),
);
}
if (gracefulStopTimeout <= 0) {
await this._connection.close();
return;
}

await this._connection.close();
try {
await this._waitEndHandlers(gracefulStopTimeout);
} catch (err) {
this._errorHandler(
EError.wrap(err, {
gracefulStopTimeout,
subMessage: 'Error at graceful disconnect',
}),
);
} finally {
await this._connection.close();
}
}

async _waitEndHandlers(gracefulStopTimeout: number) {
Expand Down

0 comments on commit f0d46a1

Please sign in to comment.