Skip to content

Commit 3ad4e1f

Browse files
docs: improve example with PM2
1 parent 0e5afee commit 3ad4e1f

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

examples/pm2-example/entrypoint.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,10 @@ io.on("connection", (socket) => {
3636
console.log(`disconnect ${socket.id} due to ${reason}`);
3737
});
3838
});
39+
40+
// graceful shutdown
41+
process.on("SIGINT", () => {
42+
io.close((err) => {
43+
process.exit(err ? 1 : 0);
44+
});
45+
});

examples/pm2-example/fastify-entrypoint.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,13 @@ fastify.addHook("preClose", (done) => {
4040
done();
4141
});
4242

43-
fastify.addHook("onClose", (_instance, done) => {
44-
io.close(done);
45-
});
46-
4743
fastify.ready(() => {
4844
console.log("successfully booted!");
4945
});
46+
47+
// graceful shutdown
48+
process.on("SIGINT", () => {
49+
fastify.close((err) => {
50+
process.exit(err ? 1 : 0);
51+
});
52+
});

0 commit comments

Comments
 (0)