async_hooks: add AsyncResource.bindCurrent()#43033
async_hooks: add AsyncResource.bindCurrent()#43033bengl wants to merge 1 commit intonodejs:masterfrom
Conversation
This static method does roughly the same thing as AsyncResource.bind(), except that it does not create a new AsyncResource. Instead, it relies on the existing current one. This is useful in situations where a callback is intended to be run in the _current_ context regardless of when/where it's called.
|
@nodejs/async_hooks |
| added: REPLACEME | ||
| --> | ||
|
|
||
| * `fn` {Function} The function to bind to the current execution context. |
There was a problem hiding this comment.
When would one use bindCurrent instead of bind ?
There was a problem hiding this comment.
Almost any time you'd think you'd want to use the static bind. It avoids the creation of a new AsyncResource instance, which in many cases isn't actually needed.
There was a problem hiding this comment.
Should we explain in the documentation when bind is actually needed?
|
Another option here would be to make |
|
Converted this to a draft, because I'd like to explore just modifying |
|
Closing this in favour of #43065. It turned out this approach (i.e. replacing the the |
This new static method does roughly the same thing as
AsyncResource.bind(), except that it does not create a newAsyncResource. Instead, it relies on the existing current one.This is an optimization useful in basically any situation where
bind()would be called without passing (or relying on) thetypeargument.I opted to make a completely different method, rather than overload
bind()even more than it already is, but I can change that if desired.