Archived
1
0

Make dispose async

This commit is contained in:
Asher 2020-07-23 12:22:38 -05:00
parent 4b6c0a6fc3
commit 58bd7008b4
No known key found for this signature in database
GPG Key ID: D63C1EF81242354A
2 changed files with 14 additions and 4 deletions

View File

@ -77,7 +77,11 @@ const main = async (args: Args, cliArgs: Args, configArgs: Args): Promise<void>
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()

View File

@ -177,7 +177,7 @@ export abstract class HttpProvider {
public constructor(protected readonly options: HttpProviderOptions) {}
public dispose(): void {
public async dispose(): Promise<void> {
// 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<Error[]> {
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<Error | undefined>(providers.map((p) => p.dispose().catch((e) => e)))
return responses.filter<Error>((r): r is Error => typeof r !== "undefined")
}
public async getConnections(): Promise<number> {