Performance: Application lifecycle
This affects the startup time and responsiveness of a NestJS application by controlling how and when components initialize and clean up.
async onModuleInit() { await Promise.all([ this.heavySetup(), this.anotherHeavyTask() ]); }
async onModuleInit() { await this.heavySetup(); await this.anotherHeavyTask(); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Sequential async initialization | N/A | N/A | Blocks main thread delaying LCP | [X] Bad |
| Parallel async initialization | N/A | N/A | Reduces blocking, improves LCP | [OK] Good |
export class AppService implements OnModuleInit, OnApplicationShutdown {
onModuleInit() {
console.log('Module initialized');
}
onApplicationShutdown(signal?: string) {
console.log('App shutting down:', signal);
}
}export class MyService implements OnApplicationShutdown {
onApplicationShutdown() {
console.log('Cleaning up');
}
}Pass the test and this pattern moves unknown