-
Notifications
You must be signed in to change notification settings - Fork 80
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
Include async functions in origins promise detection #67
base: master
Are you sure you want to change the base?
Conversation
faf4415
to
35e1897
Compare
@oshoemaker can you add a test for this bug fix? |
@fengmk2, I am not really sure how this can be tested. In our case we are using serverless web pack with target ES2018 and ESNext lib. The issue is that the test would succeed/fail based on node version/transpiler settings. So I can incorporate a test but would need to change the test environment in order to actually test this. Suggestions? |
340a8eb
to
56ab6cf
Compare
56ab6cf
to
f824927
Compare
I have added a "test" to force it to use the code and resulting output. I am not really sure if there is any other option with the current test configuration. Happy to hear suggestions though. |
@fengmk2, any update on this? |
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.
LGTM 🚀 ..
@@ -56,7 +56,8 @@ module.exports = function(options) { | |||
let origin; | |||
if (typeof options.origin === 'function') { | |||
origin = options.origin(ctx); | |||
if (origin instanceof Promise) origin = await origin; | |||
const isAsync = origin.constructor.name === 'AsyncFunction'; |
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'm not sure why we need this detect? When we call an async function, it will return a promise instance.
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.
@dead-horse , not always, the async function return a promise instance.
const p = new Promise(()=>{});
p instanceof Promise // true
const a = async function () {}
a instanceof Promise // false
a.constructor.name === "AsyncFunction" // true
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.
const a = async function () {}
const result = a()
result instanceof Promise // true
Current promise detection does not properly detect async functions in ES2018.