mirror of
https://git.tuxpa.in/a/code-server.git
synced 2024-12-27 04:35:25 +00:00
Make dispose async
This commit is contained in:
parent
4b6c0a6fc3
commit
58bd7008b4
@ -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()
|
||||
|
@ -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> {
|
||||
|
Loading…
Reference in New Issue
Block a user