From 58bd7008b47b537d94236c8f5b821f42063060da Mon Sep 17 00:00:00 2001 From: Asher Date: Thu, 23 Jul 2020 12:22:38 -0500 Subject: [PATCH] Make dispose async --- src/node/entry.ts | 6 +++++- src/node/http.ts | 12 +++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/node/entry.ts b/src/node/entry.ts index 90e5d91a4..a030cb492 100644 --- a/src/node/entry.ts +++ b/src/node/entry.ts @@ -77,7 +77,11 @@ const main = async (args: Args, cliArgs: Args, configArgs: Args): Promise httpServer.registerHttpProvider("/login", LoginHttpProvider, args.config!, envPassword) httpServer.registerHttpProvider("/static", StaticHttpProvider) - ipcMain().onDispose(() => httpServer.dispose()) + ipcMain().onDispose(() => { + httpServer.dispose().then((errors) => { + errors.forEach((error) => logger.error(error.message)) + }) + }) logger.info(`code-server ${version} ${commit}`) const serverAddress = await httpServer.listen() diff --git a/src/node/http.ts b/src/node/http.ts index 4628dd973..a4a83aeaa 100644 --- a/src/node/http.ts +++ b/src/node/http.ts @@ -177,7 +177,7 @@ export abstract class HttpProvider { public constructor(protected readonly options: HttpProviderOptions) {} - public dispose(): void { + public async dispose(): Promise { // No default behavior. } @@ -504,9 +504,15 @@ export class HttpServer { }) } - public dispose(): void { + /** + * Stop and dispose everything. Return an array of disposal errors. + */ + public async dispose(): Promise { this.socketProvider.stop() - this.providers.forEach((p) => p.dispose()) + const providers = Array.from(this.providers.values()) + // Catch so all the errors can be seen rather than just the first one. + const responses = await Promise.all(providers.map((p) => p.dispose().catch((e) => e))) + return responses.filter((r): r is Error => typeof r !== "undefined") } public async getConnections(): Promise {