Feature request, return promises
- Dominant language
- JavaScript
- Stars
- 6.4k
- Forks
- 1k
- PR merge metrics
- No merged PRs in 30d
Description
In conjunction with the callbacks, it would be nice if `session.save()` returned a promise as well. This would make in-lining session operations with if blocks, try/catch blocks and loops a lot more straightforward since async/await could be used.
For example, I'm running into race conditions with redirecting happening too soon. So in situations where I need to set the session, like a "flash" message, I have to do this:
try {
// some error prone operation
} catch(err) {
flash('error', 'something went wrong')
}
req.session.save((err) => {
res.redirect('/things')
})
You'll notice `session.save()` is called regardless of whether the error occurs. I'm choosing to do that instead of duplicate the `res.redirect()` code into multiple places.
However, what I'd rather have is:
try {
// some error prone operation
} catch(err) {
flash('error', 'something went wrong')
await req.session.save()
}
res.redirect('/things')
Contributor guide
Assessment
This issue has not been assessed yet.