-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
doc: add snippet for AsyncResource and EE integration #33751
doc: add snippet for AsyncResource and EE integration #33751
Conversation
b894b3e
to
9fa4728
Compare
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.
It may be worthwhile building this in the the EventEmitter
API (and possibly the EventTarget
API). We've talked before about adding a context
type of option to events, which could be expressed as an additional argument to addListener
/on
/once
... e.g.
const asyncResource = new AsyncResource('request');
req.on('close', () => {}, asyncResource)
Under the covers it would effectively just do exactly what this example does, but in a way that is a bit more ergonomic for the user. For instance, in order to subsequently remove the event listener, the user has to track the bound function themselves (e.g. const fn = asyncResource.runInAsyncScope.bind(asyncResource, () => {}); ee.on('foo', fn'); ee.off('foo', fn);
which is a bit cumbersome when we could handle it internally in a way similar to how we approach once
handlers.
For now, however, this example is very valuable.
9fa4728
to
0648fff
Compare
0648fff
to
ed845b8
Compare
For what it's worth, I still think having an actual method for this is friendlier, and it's simple enough that the maintenance burden is near zero. bindToAsyncScope(fn, thisArg) {
return this.runInAsyncScope.bind(this, fn, thisArg);
} I'm +0 on this. If this is how we want to proceed, that's fine. 🤷 |
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.
Yep, my perspective was just due to the other issue being closed before so it seemed like we decided against that route in favour of only documenting it. I would still like to work towards an actual fix in core. Since it seems the doc change is being considered more as a potentially temporary solution, I'll upgrade to 👍 .
PR-URL: #33751 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
Landed in db3d6b3 |
PR-URL: #33751 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
PR-URL: #33751 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
PR-URL: #33751 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
PR-URL: #33751 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
Continuation of #33736
Adds a snippet for
AsyncResource
+EventEmitter
integration, based onasyncResource.runInAsyncScope.bind
.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes