Skip to content

Commit 58bd700

Browse files
committed
Make dispose async
1 parent 4b6c0a6 commit 58bd700

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/node/entry.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ const main = async (args: Args, cliArgs: Args, configArgs: Args): Promise<void>
7777
httpServer.registerHttpProvider("/login", LoginHttpProvider, args.config!, envPassword)
7878
httpServer.registerHttpProvider("/static", StaticHttpProvider)
7979

80-
ipcMain().onDispose(() => httpServer.dispose())
80+
ipcMain().onDispose(() => {
81+
httpServer.dispose().then((errors) => {
82+
errors.forEach((error) => logger.error(error.message))
83+
})
84+
})
8185

8286
logger.info(`code-server ${version} ${commit}`)
8387
const serverAddress = await httpServer.listen()

src/node/http.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export abstract class HttpProvider {
177177

178178
public constructor(protected readonly options: HttpProviderOptions) {}
179179

180-
public dispose(): void {
180+
public async dispose(): Promise<void> {
181181
// No default behavior.
182182
}
183183

@@ -504,9 +504,15 @@ export class HttpServer {
504504
})
505505
}
506506

507-
public dispose(): void {
507+
/**
508+
* Stop and dispose everything. Return an array of disposal errors.
509+
*/
510+
public async dispose(): Promise<Error[]> {
508511
this.socketProvider.stop()
509-
this.providers.forEach((p) => p.dispose())
512+
const providers = Array.from(this.providers.values())
513+
// Catch so all the errors can be seen rather than just the first one.
514+
const responses = await Promise.all<Error | undefined>(providers.map((p) => p.dispose().catch((e) => e)))
515+
return responses.filter<Error>((r): r is Error => typeof r !== "undefined")
510516
}
511517

512518
public async getConnections(): Promise<number> {

0 commit comments

Comments
 (0)