From 5f5d3c1b0437a8c9506b2af6ee6267d4a7e84379 Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Thu, 7 Dec 2023 07:03:29 +0000 Subject: [PATCH] Clean up listener after cli run --- FlowPluginsTs/FlowHelpers/1.0.0/cliUtils.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/FlowPluginsTs/FlowHelpers/1.0.0/cliUtils.ts b/FlowPluginsTs/FlowHelpers/1.0.0/cliUtils.ts index 925b498..fcd074a 100644 --- a/FlowPluginsTs/FlowHelpers/1.0.0/cliUtils.ts +++ b/FlowPluginsTs/FlowHelpers/1.0.0/cliUtils.ts @@ -278,20 +278,22 @@ class CLI { // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/explicit-module-boundary-types let thread: any; - process.on('exit', () => { + const exitHandler = () => { if (thread) { try { - // eslint-disable-next-line no-console + // eslint-disable-next-line no-console console.log('Main thread exiting, cleaning up running CLI'); this.killThread(thread); } catch (err) { - // eslint-disable-next-line no-console + // eslint-disable-next-line no-console console.log('Error running cliUtils on Exit function'); // eslint-disable-next-line no-console console.log(err); } } - }); + }; + + process.on('exit', exitHandler); const cliExitCode: number = await new Promise((resolve) => { try { @@ -334,6 +336,8 @@ class CLI { } }); + process.removeListener('exit', exitHandler); + thread = undefined; if (!this.config.logFullCliOutput) {