If you don't want the response to wait for the database operation to complete, then you can do either of these:
// remove the await so you don't wait for the query to finish
router.get('/test', (req, res) => {
querySources(req.query.id, req.query.name).catch(...)
res.status(500).json({message: "success"})
}
or
// send the response immediately, then do the database stuff
router.get('/test', (req, res) => {
res.status(500).json({message: "success"})
querySources(req.query.id, req.query.name).catch(...)
}
Note, you will need some ability to catch any error that querySources()
has so that error doesn't go unhandled. Probably you just need to log it since the client can't be notified at this point.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…