feat: stopped state in application (#1543)
This commit is contained in:
parent
2e4354fcf3
commit
db6d572638
@ -172,6 +172,8 @@ export class Application<StateT = DefaultState, ContextT = DefaultContext> exten
|
|||||||
|
|
||||||
declare middleware: any;
|
declare middleware: any;
|
||||||
|
|
||||||
|
stopped: boolean = false;
|
||||||
|
|
||||||
constructor(public options: ApplicationOptions) {
|
constructor(public options: ApplicationOptions) {
|
||||||
super();
|
super();
|
||||||
this.init();
|
this.init();
|
||||||
@ -434,6 +436,7 @@ export class Application<StateT = DefaultState, ContextT = DefaultContext> exten
|
|||||||
}
|
}
|
||||||
|
|
||||||
await this.emitAsync('afterStart', this, options);
|
await this.emitAsync('afterStart', this, options);
|
||||||
|
this.stopped = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
listen(...args): Server {
|
listen(...args): Server {
|
||||||
@ -441,6 +444,11 @@ export class Application<StateT = DefaultState, ContextT = DefaultContext> exten
|
|||||||
}
|
}
|
||||||
|
|
||||||
async stop(options: any = {}) {
|
async stop(options: any = {}) {
|
||||||
|
if (this.stopped) {
|
||||||
|
this.log.warn(`Application ${this.name} already stopped`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await this.emitAsync('beforeStop', this, options);
|
await this.emitAsync('beforeStop', this, options);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -460,6 +468,7 @@ export class Application<StateT = DefaultState, ContextT = DefaultContext> exten
|
|||||||
}
|
}
|
||||||
|
|
||||||
await this.emitAsync('afterStop', this, options);
|
await this.emitAsync('afterStop', this, options);
|
||||||
|
this.stopped = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async destroy(options: any = {}) {
|
async destroy(options: any = {}) {
|
||||||
|
Loading…
Reference in New Issue
Block a user