Open
Description
As a general best practice, to avoid unnecessary performance cost, purely sync async functions should be avoided.
For instance, from https://github.com/covidgreen/covid-green-backend-api/blob/current/lib/server.js:
server.addHook('onSend', async (req, res) => {
res.header('Cache-Control', 'no-store')
res.header('Pragma', 'no-cache')
res.header(
'Strict-Transport-Security',
`max-age=${config.security.hstsMaxAge}; includeSubDomains`
)
})
The hook function is not doing anything asynchronous and therefore should not be an async function:
server.addHook('onSend', (req, res, done) => {
res.header('Cache-Control', 'no-store')
res.header('Pragma', 'no-cache')
res.header(
'Strict-Transport-Security',
`max-age=${config.security.hstsMaxAge}; includeSubDomains`
)
done()
})
The anti-pattern of using async functions with sync code is seen several places throughout the code.
Metadata
Assignees
Labels
No labels