session icon indicating copy to clipboard operation
session copied to clipboard

Added: Promise return type for req.session.save() function

Open NrI3 opened this issue 6 years ago • 3 comments

NrI3 avatar Oct 11 '19 10:10 NrI3

ping

salisbury-espinosa avatar Jun 21 '21 05:06 salisbury-espinosa

What could be done to get this PR integrated?

sgnl avatar Jun 11 '22 04:06 sgnl

One workaround is to add the promisified function via middleware:

import { promisify } from 'util';

...

// make "saveAsync" available to other routes
// could also be done via app.use()
router.use((req, _res, next) => {
    req.session.saveAsync = promisify(req.session.save.bind(req.session));
    next();
  });

...

router.post('/xyz', async (req, res, next)  => {
   await req.session.saveAsync();
   
   // do more stuff
});
  

twelve17 avatar May 19 '23 00:05 twelve17