Skip to content

Commit 15c5f08

Browse files
author
Matija Petrunic
committed
Make node cleanup respect async functions
1 parent 4c37eef commit 15c5f08

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/App.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ export class App {
5151
});
5252
}
5353

54-
public async stop(): Promise<void> {
54+
public async stop(signal: string): Promise<void> {
5555
await this.instance.close();
56+
process.kill(process.pid, signal);
5657
}
5758

5859
private registerPlugins(): void {
@@ -88,4 +89,4 @@ declare module "fastify" {
8889
config: Config;
8990
db: Connection;
9091
}
91-
}
92+
}

src/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import nodeCleanup from "node-cleanup";
33

44
const app = new App();
55

6-
nodeCleanup(function () {
7-
app.stop();
6+
nodeCleanup(function (exitCode, signal) {
7+
app.stop(signal as string);
8+
nodeCleanup.uninstall();
9+
return false;
810
});
911

10-
app.start();
12+
app.start();

0 commit comments

Comments
 (0)