Make dispose async

This commit is contained in:
Asher
2020-07-23 12:22:38 -05:00
parent 4b6c0a6fc3
commit 58bd7008b4
2 changed files with 14 additions and 4 deletions

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> {