diff --git a/README.md b/README.md index a1ed3fa1..ac2955a9 100644 --- a/README.md +++ b/README.md @@ -368,6 +368,18 @@ req.session.save(function(err) { }) ``` +#### Session.save().then(callback) + +You can use Promise type as return + +Example +```js +await req.session.save() +.then(()=>{ + // session saved +}) +``` + #### Session.touch() Updates the `.maxAge` property. Typically this is diff --git a/index.js b/index.js index 24221b48..3e7aed95 100644 --- a/index.js +++ b/index.js @@ -393,6 +393,7 @@ function session(options) { debug('saving %s', this.id); savedHash = hash(this); _save.apply(this, arguments); + return this.req.sessionStore.setPromise; } Object.defineProperty(sess, 'reload', { diff --git a/session/session.js b/session/session.js index fee7608c..2009773e 100644 --- a/session/session.js +++ b/session/session.js @@ -69,7 +69,7 @@ defineMethod(Session.prototype, 'resetMaxAge', function resetMaxAge() { */ defineMethod(Session.prototype, 'save', function save(fn) { - this.req.sessionStore.set(this.id, this, fn || function(){}); + this.req.sessionStore.setPromise = this.req.sessionStore.set(this.id, this, fn || function(){}); return this; });