-
Notifications
You must be signed in to change notification settings - Fork 75
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
[Proposal] fix: use friendlier promise checking #84
Conversation
@fengmk2 would love any feedback on this PR |
@fengmk2 bumping this PR :) |
@smolster Can you add a test case to cover this change? |
index.js
Outdated
@@ -62,17 +62,15 @@ module.exports = function(options) { | |||
|
|||
let origin; | |||
if (typeof options.origin === 'function') { | |||
origin = options.origin(ctx); | |||
if (origin instanceof Promise) origin = await origin; | |||
origin = await Promise.resolve().then(() => options.origin(ctx)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
origin could be a normal function, why we need to change it to a promise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're asking "why would we use Promise.resolve().then(...)
" instead of just using await options.origin(ctx)
. I updated to use that simpler syntax.
If that's not what you're asking, could you elaborate a little more on your question?
@fengmk2 tests added 👍🏻 -- apologies for leaving it off at first. |
1a5527d
to
22c3d11
Compare
@fengmk2 bumping this fix |
@fengmk2 any update on this PR? |
@fengmk2 coming up on 2 months since this PR has been opened. Is it safe to merge now? |
@fengmk2 3 months since this PR opened :/ -- think we can merge it? |
@swain I will add more tests before npm publish. |
3.4.0 |
Motivation
The current syntax is not friendly to scenarios where the global
Promise
object may have been re-mapped to a different class, and async functions are being used. Example:This syntax should be more resilient against weird Promise scenarios, including this one.