-
Notifications
You must be signed in to change notification settings - Fork 30k
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
AsyncResource.bind
always alters the value of this
unexpectedly
#42158
Comments
|
I agree that this is not nice and would prefer to have it different. But I guess a change would be semver major as |
I've been trying to understand the reasoning behind this, and the only thing I can think of is that for the static Maybe @jasnell can provide the reasoning behind the current implementation, but right now I can't really think of a single use case (outside of maybe Node core and As for semver, I think it depends if this is bad enough to warrant making it a bug fix since it overrides the value of In any case, I can work on a PR if everyone agrees that not binding |
The static The current doc doesn't state that |
@Flarna I'm not sure when you want to ignore the |
I have also no use case in mind and for me patch/bug is fine. |
Version
17.6.0
Platform
No response
Subsystem
No response
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
Always as the code is explicitly binding
thisArg
even when not provided.What is the expected behavior?
AsyncResource.bind
should use thethis
value provided by the caller by default and only bindthis
when athisArg
is passed explicitly.What do you see instead?
AsyncResource.bind
defaults to settingthis
to itself, which is not only unexpected in pretty much all cases, but also makes it impossible to use thethis
provided by the caller without an explicit reference to the caller at bind time. This means that in all situations right now it would make more sense to userunInAsyncScope
instead ofbind
making it effectively unusable.Additional information
As an APM vendor, we're making heavy use of this API and there is not a single occurrence in our code where the default works.
The feature was originally implemented in #36782
The text was updated successfully, but these errors were encountered: