Skip to content

Commit

Permalink
feat(rpc/service): shutdown process on disconnect in service adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
CheerlessCloud committed Oct 4, 2018
1 parent f0d46a1 commit 4097905
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,13 @@ class RpcService extends AdapterConsumer {
stopSignal = 'SIGINT',
gracefulStopTimeout = 60 * 1000,
}: { stopSignal?: string, gracefulStopTimeout?: number } = {}) {
let shutdownInProcess = false;
const endCallback = async () => {
if (shutdownInProcess) {
return;
}
shutdownInProcess = true;

try {
await this.destroy({ gracefulStopTimeout });
process.exit(0);
Expand All @@ -170,6 +176,10 @@ class RpcService extends AdapterConsumer {
};

process.once(stopSignal, endCallback);

const adapter = this._getAdapter();
// @todo exit with status 0
adapter._eventBus.once('disconnect', endCallback);
}
}

Expand Down

0 comments on commit 4097905

Please sign in to comment.