Skip to content

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

Closed
NrI3 wants to merge 5 commits into
expressjs:masterfrom
NrI3:master
Closed

Added: Promise return type for req.session.save() function#701
NrI3 wants to merge 5 commits into
expressjs:masterfrom
NrI3:master

Conversation

@NrI3

@NrI3 NrI3 commented Oct 11, 2019

Copy link
Copy Markdown

No description provided.

NrI3 added 5 commits October 11, 2019 03:53
Add Promise type object for use as Promise return in req.session.save()
Now we can use req.session.save() function as promise example

await req.session.save()
    .then(()=>{
        console.log('saved')
    })
    .catch(()=>{
        console.log('error')
    })
@salisbury-espinosa

Copy link
Copy Markdown

ping

@ghost

ghost commented Jun 11, 2022

Copy link
Copy Markdown

What could be done to get this PR integrated?

@twelve17

Copy link
Copy Markdown

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
});
  

@bjohansebas

Copy link
Copy Markdown
Member

closes in favor of #737

@bjohansebas bjohansebas closed this Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants