-
Notifications
You must be signed in to change notification settings - Fork 461
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
utils: Override async functions with async functions #2163
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -322,9 +322,16 @@ export class InjectionsHandler extends BasicHandler { | |
if (!(original instanceof Function)) | ||
throw new Error(`Virtual function ${name}() is not available for ${object}`); | ||
|
||
object[name] = function (...args) { | ||
return injectedFunction.call(this, original, ...args); | ||
}; | ||
if (original.constructor.name === 'AsyncFunction') { | ||
// eslint-disable-next-line require-await | ||
object[name] = async function (...args) { | ||
return injectedFunction.call(this, original, ...args); | ||
}; | ||
Comment on lines
+327
to
+329
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, if you're declaring this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} else { | ||
object[name] = function (...args) { | ||
return injectedFunction.call(this, original, ...args); | ||
}; | ||
} | ||
return [object, name, original]; | ||
} | ||
|
||
|
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.
Oh, funny thing... I had this changed months ago and I forgot to commit...
However, define something like
const AsyncFunctionType = (async () => {}).constructor;
and then check fororiginal instanceof AsyncFunctionType
.Also I feel we should check if the two things match, so if both the original ones are async or not and depending on that behave differently.
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 saw that suggestion when googling but it felt like a hack so I intentionally didn't do it that way. It's uglier, more code, and not obviously correct to me.
Good point about checking two things match though...
Since it turns out the bug #2110 actually isn't important, and it's fixed by #2166, and you have another fix in mind, I suggest just merging your own fix or wait for #2166.