Prechádzať zdrojové kódy

fix(home-server): unref the server instance when stopping the home server

Karol Sójko 2 rokov pred
rodič
commit
5ef90cc75b

+ 13 - 2
packages/home-server/src/Server/HomeServer.ts

@@ -159,9 +159,20 @@ export class HomeServer implements HomeServerInterface {
     }
   }
 
-  async stop(): Promise<void> {
-    if (this.serverInstance) {
+  async stop(): Promise<Result<string>> {
+    try {
+      if (!this.serverInstance) {
+        return Result.fail('Home server is not running.')
+      }
+
       this.serverInstance.close()
+      this.serverInstance.unref()
+
+      this.serverInstance = undefined
+
+      return Result.ok('Server stopped.')
+    } catch (error) {
+      return Result.fail((error as Error).message)
     }
   }
 

+ 1 - 1
packages/home-server/src/Server/HomeServerInterface.ts

@@ -4,7 +4,7 @@ import { HomeServerConfiguration } from './HomeServerConfiguration'
 export interface HomeServerInterface {
   start(configuration?: HomeServerConfiguration): Promise<Result<string>>
   activatePremiumFeatures(username: string): Promise<Result<string>>
-  stop(): Promise<void>
+  stop(): Promise<Result<string>>
   isRunning(): Promise<boolean>
   logs(): NodeJS.ReadableStream
 }