diff --git a/src/index.ts b/src/index.ts index 0569913..4443c13 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,7 +3,7 @@ import { start as startRelay } from "./modules/relay.js"; import { start as startApp } from "./modules/app"; import config from "./config.js"; import { loadPlugins } from "./modules/plugin.js"; -import { start as startSwarm } from "./modules/swarm.js"; +import { start as startSwarm, get as getSwarm } from "./modules/swarm.js"; import * as bip39 from "@scure/bip39"; import { wordlist } from "@scure/bip39/wordlists/english"; @@ -26,9 +26,11 @@ boot(); process.on("uncaughtException", function (err) { console.log(`Caught exception: ${err.message} ${err.stack}`); }); -process.on("SIGINT", function () { + +async function shutdown() { + await getSwarm().destroy(); process.exit(); -}); -process.on("SIGTERM", function () { - process.exit(); -}); +} + +process.on("SIGINT", shutdown); +process.on("SIGTERM", shutdown);