Skip to content

Commit

Permalink
refactor: uninstall global listeners not needed on eject templates (#732
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jean-michelet authored Jun 11, 2024
1 parent 1d29264 commit 83c9ca2
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 24 deletions.
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,13 @@ const appService = require('./app.js')
app.register(appService)

// delay is the number of milliseconds for the graceful close to finish
const closeListeners = closeWithGrace({ delay: process.env.FASTIFY_CLOSE_GRACE_DELAY || 500 }, async function ({ signal, err, manual }) {
closeWithGrace({ delay: process.env.FASTIFY_CLOSE_GRACE_DELAY || 500 }, async function ({ signal, err, manual }) {
if (err) {
app.log.error(err)
}
await app.close()
})

app.addHook('onClose', (instance, done) => {
closeListeners.uninstall()
done()
})

// Start listening.
app.listen({ port: process.env.PORT || 3000 }, (err) => {
if (err) {
Expand Down
7 changes: 1 addition & 6 deletions templates/eject-esm/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,13 @@ const app = Fastify({
app.register(appService)

// delay is the number of milliseconds for the graceful close to finish
const closeListeners = closeWithGrace({ delay: process.env.FASTIFY_CLOSE_GRACE_DELAY || 500 }, async function ({ signal, err, manual }) {
closeWithGrace({ delay: process.env.FASTIFY_CLOSE_GRACE_DELAY || 500 }, async function ({ signal, err, manual }) {
if (err) {
app.log.error(err)
}
await app.close()
})

app.addHook('onClose', (instance, done) => {
closeListeners.uninstall()
done()
})

// Start listening.
app.listen({ port: process.env.PORT || 3000 }, (err) => {
if (err) {
Expand Down
7 changes: 1 addition & 6 deletions templates/eject-ts/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,13 @@ const app = Fastify({
app.register(import("./app"));

// delay is the number of milliseconds for the graceful close to finish
const closeListeners = closeWithGrace({ delay: parseInt(process.env.FASTIFY_CLOSE_GRACE_DELAY) || 500 }, async function ({ signal, err, manual }) {
closeWithGrace({ delay: parseInt(process.env.FASTIFY_CLOSE_GRACE_DELAY) || 500 }, async function ({ signal, err, manual }) {
if (err) {
app.log.error(err)
}
await app.close()
} as closeWithGrace.CloseWithGraceAsyncCallback)

app.addHook('onClose', (instance, done) => {
closeListeners.uninstall()
done()
})

// Start listening.
app.listen({ port: parseInt(process.env.PORT) || 3000 }, (err: any) => {
if (err) {
Expand Down
7 changes: 1 addition & 6 deletions templates/eject/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,13 @@ const appService = require('./app.js')
app.register(appService)

// delay is the number of milliseconds for the graceful close to finish
const closeListeners = closeWithGrace({ delay: process.env.FASTIFY_CLOSE_GRACE_DELAY || 500 }, async function ({ signal, err, manual }) {
closeWithGrace({ delay: process.env.FASTIFY_CLOSE_GRACE_DELAY || 500 }, async function ({ signal, err, manual }) {
if (err) {
app.log.error(err)
}
await app.close()
})

app.addHook('onClose', (instance, done) => {
closeListeners.uninstall()
done()
})

// Start listening.
app.listen({ port: process.env.PORT || 3000 }, (err) => {
if (err) {
Expand Down

0 comments on commit 83c9ca2

Please sign in to comment.