From 01ca4aae5ab25afa0ffee736def522cd1b47c7a7 Mon Sep 17 00:00:00 2001 From: MiTask Date: Fri, 14 Jun 2024 08:43:27 +0000 Subject: [PATCH] Update chatBot/includes/Client.js --- chatBot/includes/Client.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/chatBot/includes/Client.js b/chatBot/includes/Client.js index 8713fb4..dbc5c08 100644 --- a/chatBot/includes/Client.js +++ b/chatBot/includes/Client.js @@ -19,20 +19,18 @@ class Client extends EventEmitter { this.destroy(); }); - process.on('SIGTERM', () => { + process.on('SIGTERM', async () => { console.log('SIGTERM signal received. Shutting down HyperSwarm...'); - this.destroy().then(() => { - console.log('HyperSwarm was shut down. Exiting the process with exit code 0.'); - process.exit(0); - }); + await this.destroy() + console.log('HyperSwarm was shut down. Exiting the process with exit code 0.'); + process.exit(0); }); - process.on('SIGINT', () => { + process.on('SIGINT', async () => { console.log('SIGINT signal received. Shutting down HyperSwarm...'); - this.destroy().then(() => { - console.log('HyperSwarm was shut down. Exiting the process with exit code 0.'); - process.exit(0); - }); + await this.destroy() + console.log('HyperSwarm was shut down. Exiting the process with exit code 0.'); + process.exit(0); }); } @@ -89,8 +87,8 @@ class Client extends EventEmitter { for (const peer of peers) peer.write(data); } - destroy() { - this.swarm.destroy(); + async destroy() { + await this.swarm.destroy(); console.log(`Bot ${this.botName} disconnected.`); } }