From db6d57263892809fc08d35ec4cfb186971a796ef Mon Sep 17 00:00:00 2001 From: ChengLei Shao Date: Mon, 6 Mar 2023 21:19:49 +0800 Subject: [PATCH] feat: stopped state in application (#1543) --- packages/core/server/src/application.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/core/server/src/application.ts b/packages/core/server/src/application.ts index 74fce85b8..739cb4e67 100644 --- a/packages/core/server/src/application.ts +++ b/packages/core/server/src/application.ts @@ -172,6 +172,8 @@ export class Application exten declare middleware: any; + stopped: boolean = false; + constructor(public options: ApplicationOptions) { super(); this.init(); @@ -434,6 +436,7 @@ export class Application exten } await this.emitAsync('afterStart', this, options); + this.stopped = false; } listen(...args): Server { @@ -441,6 +444,11 @@ export class Application exten } async stop(options: any = {}) { + if (this.stopped) { + this.log.warn(`Application ${this.name} already stopped`); + return; + } + await this.emitAsync('beforeStop', this, options); try { @@ -460,6 +468,7 @@ export class Application exten } await this.emitAsync('afterStop', this, options); + this.stopped = true; } async destroy(options: any = {}) {