-
-
Notifications
You must be signed in to change notification settings - Fork 978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support returning promises on Session prototype methods #737
base: master
Are you sure you want to change the base?
Conversation
…esolve linting errors
…rsion 2017 to eslintrc
Hey there thanks for the contribution! I agree that promises are a pretty typical part of most modern libraries, and it would make sense to see them supported with First, this would be a breaking change (no longer returning I'm opposed to the approach of returning a Promise even when a callback is provided. You end up with unhandled Promise rejections if you're only using callbacks. Running the tests for this PR, you can see that several of the tests are giving warnings about unhandled promise rejections. I prefer the approach in #635 where you get either a Promise or a callback as resolution. |
This is just some feedback, I'm not a maintainer of this Repo. But @ghinks and @gireeshpunathil are getting more directly involved in this project and I'd look to them to discuss what's coming next and what they'd want to see out of Promises for |
If it helps @jonchurch I have the exact same general feedback you just posted. I was waiting for one of you folks to post before me :) The promise rejections that occur when users are using the callback API is of the biggest concern for sure. |
…chaining functionality if callback provided as opposed to promise being returned
Fair enough @jonchurch and @dougwilson, I made changes to only return promises if a callback is not provided to prevent unhandled rejections and reinstate returning For any existing repos using callbacks their chaining would not break, but any new repos wanting to use promises with these methods can simply chain their promises together with |
@whatl3y Good work! I didn't even consider you could just return |
So for some background @jonchurch , it unfortunately will as long as there are changes that expect a specific base class change to be in another store module. We found this out in the original Promises PR as an issue (I was working physically together with that author). For example, a store will need to inherit the This presents the situation of the current API: the calls that are made on |
The current implementation, though it does this, is still not backwards compatible, though, as many of those methods do not require a callback, but would still have returned |
Darn, this makes sense @dougwilson. I guess short of implementing a custom Let me know if you guys think of anything creative or need help with anything else in the meantime. |
What about adding (I couldn't see this mentioned in the linked issues/PRs, apologies if it has been). For now I promisify manually when I need to: const { promisify } = require('util');
async function destroySession(req) {
const session = req.session;
await promisify(session.destory.bind(session))();
} |
Any movement on this feature? |
Would very much like to have this implemented. |
9d2e29b
to
408229e
Compare
Resolves issues #547, #607
This branch is similar to PRs #701 and #635 but with passing tests and test coverage, in addition to ensuring all methods return promises always, not only when there isn't a callback (I'm unsure why #635 only returns promises when there are no callbacks as returning a promise in this case doesn't harm anything, but let me know if I'm missing something).
This PR keeps the existing functionality with callbacks in tact, but now returns promises for the following prototype methods on
Session
.Session.prototype.save
Session.prototype.reload
Session.prototype.destroy
Session.prototype.regenerate
This removes the ability to "chain" these methods together as was the original behavior, but not only was this chaining not being used anywhere in the repo, it doesn't really make sense to chain async methods together unless they're chains of returned promises. If I'm missing some historical context as to why this was the original behavior please correct me.
This also adds bluebird as a dependency for older versions of NodeJS that don't have promises in the standard library, but considering these older versions of NodeJS are either not supported anymore or won't be in the near future it might be worth removing as a dependency and just assuming Promise exists without falling back.