From 831612bc77c68cf6433a111bbd299e40d2f3a0be Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 5 Jan 2023 19:39:03 -0500 Subject: [PATCH] *Add an async shutdown event so that plugins can take action before the swarm is destroyed --- src/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 4443c13..2176f1b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,7 @@ import { start as startRpc } from "./modules/rpc.js"; 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 { getPluginAPI, loadPlugins } from "./modules/plugin.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"; @@ -28,6 +28,7 @@ process.on("uncaughtException", function (err) { }); async function shutdown() { + await getPluginAPI().emitAsync("core.shutdown"); await getSwarm().destroy(); process.exit(); }