Skip to content

doc: add snippet for AsyncResource and EE integration - #33751

Closed
puzpuzpuz wants to merge 1 commit into
nodejs:masterfrom
puzpuzpuz:doc/add-async-resource-bind-sample
Closed

doc: add snippet for AsyncResource and EE integration#33751
puzpuzpuz wants to merge 1 commit into
nodejs:masterfrom
puzpuzpuz:doc/add-async-resource-bind-sample

Conversation

@puzpuzpuz

Copy link
Copy Markdown
Member

Continuation of #33736

Adds a snippet for AsyncResource + EventEmitter integration, based on asyncResource.runInAsyncScope.bind.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • documentation is changed or added
  • commit message follows commit guidelines

@puzpuzpuzpuzpuzpuz added the async_hooks Issues and PRs related to the async hooks subsystem. label Jun 5, 2020
@nodejs-github-botnodejs-github-bot added the doc Issues and PRs related to the documentations. label Jun 5, 2020
@puzpuzpuz
puzpuzpuzforce-pushed the doc/add-async-resource-bind-sample branch from b894b3e to 9fa4728CompareJune 5, 2020 14:02
@puzpuzpuz
puzpuzpuz marked this pull request as ready for review June 5, 2020 14:02

@jasnelljasnell left a comment

Copy link
Copy Markdown
Member

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.

constasyncResource=newAsyncResource('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.

Comment threaddoc/api/async_hooks.md Outdated
Comment threaddoc/api/async_hooks.md Outdated
@puzpuzpuz
puzpuzpuzforce-pushed the doc/add-async-resource-bind-sample branch from 9fa4728 to 0648fffCompareJune 5, 2020 17:14
Comment threadtest0.js Outdated
@puzpuzpuz
puzpuzpuzforce-pushed the doc/add-async-resource-bind-sample branch from 0648fff to ed845b8CompareJune 5, 2020 17:23
@Qard

Qard commented Jun 6, 2020

Copy link
Copy Markdown
Member

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){returnthis.runInAsyncScope.bind(this,fn,thisArg);}

I'm +0 on this. If this is how we want to proceed, that's fine. 🤷

@puzpuzpuz

Copy link
Copy Markdown
MemberAuthor

@Qard optimistically, this doc addition is a temp measure while EEs/streams used in the core are not integrated properly with async_hooks (see #33723). Once they're integrated (hopefully, this is going to happen), it's easy to remove this addition.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Qard
Qard approved these changes Jun 8, 2020

@QardQard left a comment

Copy link
Copy Markdown
Member

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 👍 .

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/31827/

puzpuzpuz added a commit that referenced this pull request Jun 11, 2020
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>
@puzpuzpuz

Copy link
Copy Markdown
MemberAuthor

Landed in db3d6b3

@puzpuzpuz
puzpuzpuz deleted the doc/add-async-resource-bind-sample branch June 11, 2020 09:17
codebytere pushed a commit that referenced this pull request Jun 18, 2020
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>
@codebyterecodebytere mentioned this pull request Jun 28, 2020
codebytere pushed a commit that referenced this pull request Jun 30, 2020
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>
codebytere pushed a commit that referenced this pull request Jul 10, 2020
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>
@codebyterecodebytere mentioned this pull request Jul 13, 2020
codebytere pushed a commit that referenced this pull request Jul 14, 2020
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>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

async_hooksIssues and PRs related to the async hooks subsystem.docIssues and PRs related to the documentations.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants

@puzpuzpuz@Qard@nodejs-github-bot@jasnell@benjamingr@ronag@vdeturckheim@lundibundi@Flarna