Skip to content

Conversation

@thlorenz
Copy link
Owner

@thlorenz thlorenz commented Nov 28, 2016

WIP PR to get Feedback.

@rvagg @Fishrock123 @trevnorris

Copy link

@trevnorris trevnorris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs will need to be word wrapped before going into core. I'll let you decide when to take care of that.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the value inside of the {} is usually capitalized in core docs at least.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool will fix

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parentUid -> triggerId

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: should we automatically stop listening in the 'exit' event?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd opt for not doing any magic here. It doesn't matter much anyways since the process is exiting ...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should either be asyncHook.enable() or AsyncHook#enable(). Like this it looks like a static member (i.e. not one on the prototype).

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which one of these two is more common given this is a module method? cc @Fishrock123

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "current execution context". remove a hair more ambiguity.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The preferred embedder API is to use AsyncEvent. The async_hooks.emitInit(), etc., were made for internals, but I could find reasonable need for them in user code. But want to make clear they should attempt to use AsyncEvent first, if possible.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK will dig into that a bit more AsyncEvent and update the docs as far as I'll understand things at that point ...

@thlorenz thlorenz force-pushed the trevnorris-async-wrap-eps-impl+docs branch from cb4c5f2 to 8745613 Compare January 4, 2017 15:16
@thlorenz thlorenz force-pushed the trevnorris-async-wrap-eps-impl branch from f068849 to 620fb61 Compare January 5, 2017 14:27

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a terminology section: https://github.com/nodejs/node-eps/blob/e35d4813fdbbd99a751296e24361dba0d0dd9e10/XXX-asyncwrap-api.md#terminology

The top-level description should probably not include the word "handle".

Copy link

@Fishrock123 Fishrock123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, al the Node.js docs follow some order:

All sections and content within them must be alphabetical, the exception being if you have API and subheadings in the same spot, then the API references must be alphabetical but the sub-heading should usually go last.

Also, we tend to put examples after API references, except in the case of a top-level example.

@thlorenz thlorenz force-pushed the trevnorris-async-wrap-eps-impl+docs branch from 8745613 to 13c8190 Compare January 17, 2017 16:01
@thlorenz
Copy link
Owner Author

@Fishrock123 @trevnorris, ready for another review. Fixed a bunch of nits and integrated big parts from the EPS

Most now comes from this EPS, except I reordered things a bit to clearly separate the different parts of the API.
I also removed some parts that described implementation details not useful to the users.

I also removed the original example I had in there, as now lots of examples are already included in numerous places.

LMK what you think at this point.

@thlorenz thlorenz force-pushed the trevnorris-async-wrap-eps-impl branch 4 times, most recently from 97194bd to 7dae377 Compare January 25, 2017 21:22
@thlorenz thlorenz force-pushed the trevnorris-async-wrap-eps-impl+docs branch from 175108c to df8e8e5 Compare January 26, 2017 16:28
Copy link

@Fishrock123 Fishrock123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would also be good to have a section explaining that you must sue process._rawDebug() to log within a look so as to prevent an infinite loop.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra spaces?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you clarify? Missing spaces, need to add them and where?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tasks, such as -- the last sentence probably shouldn't be it's own.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK will fix.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean retrieving the handle if the user has stored it?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably be id instead of handle .. I agree it's confusing.
This came from the EP (slightly adapted) so @trevnorris should know.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... retrieving the handle of the current trigger

That comment dates back to when I had implemented a map to keep track of all resources, and there was async_hooks.getResourceById(). Which would return the resource from the map, but it ended up being too costly. So it was removed.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a new AsyncHook instance.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hairsplitting, but I've got no strong opinion, so will fix.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will actually prevent those

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need clarification from @trevnorris here.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the EP to simply say:

// Disable listening for all new asynchronous events.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

returned from `currentId()`

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we want to put in a thing about that I/O pools need to use this?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need more details on that or maybe you or @trevnorris can suggest the addition here?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fishrock123 can you clarify what you mean?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this comment should go under the actual api header with an example?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, makes sense. Will fix.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

async

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The argument names are supposed to be surrounded in backticks. e.g. `type`. Please change throughout the document.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should say it should not be called or an example given?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not fully sure what you mean. What should not be called?

@thlorenz thlorenz force-pushed the trevnorris-async-wrap-eps-impl+docs branch from df8e8e5 to b3aed32 Compare January 26, 2017 19:33
@thlorenz thlorenz force-pushed the trevnorris-async-wrap-eps-impl branch from 33c2eb5 to 97a27f1 Compare January 27, 2017 15:29
@thlorenz thlorenz force-pushed the trevnorris-async-wrap-eps-impl+docs branch from b3aed32 to dc4833d Compare January 27, 2017 15:30
Copy link

@trevnorris trevnorris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the work. I like the added example of using the AsyncEvent API.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the initial release will be labeled 1 - Experimental so that we have a major version to make any necessary tweaks.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't make much sense to me. The absolute simplest would be to log metadata about asynchronous resources when they occur.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the paragraph

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... retrieving the handle of the current trigger

That comment dates back to when I had implemented a map to keep track of all resources, and there was async_hooks.getResourceById(). Which would return the resource from the map, but it ended up being too costly. So it was removed.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the EP to simply say:

// Disable listening for all new asynchronous events.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that is removed I'd suggest explicitly mentioning all four callbacks. e.g.

The callbacks init()/before()/after()/destroy() are registered via...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you add that console.*() should never be used from hook callbacks? May need to mention this.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script above, and this output, were both updated in the EP. Please reference.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the output .. didn't see any changes to the script.
Note that we're using class like function declarations (instead of arrow functions) as per request by @Fishrock123

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's anything that uses MakeWeak() in C++. Can throw that list together if needed.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fishrock123 can you clarify what you mean?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The argument names are supposed to be surrounded in backticks. e.g. `type`. Please change throughout the document.

@thlorenz
Copy link
Owner Author

@thlorenz thlorenz force-pushed the trevnorris-async-wrap-eps-impl branch from 97a27f1 to 79b11ce Compare February 1, 2017 15:15
@thlorenz thlorenz force-pushed the trevnorris-async-wrap-eps-impl+docs branch from 17edc94 to e5193f7 Compare February 1, 2017 15:16
@thlorenz thlorenz force-pushed the trevnorris-async-wrap-eps-impl branch from 79b11ce to 1ff2dfb Compare February 2, 2017 15:44
@thlorenz thlorenz force-pushed the trevnorris-async-wrap-eps-impl+docs branch from e5193f7 to 4dac48a Compare February 2, 2017 15:50
@thlorenz
Copy link
Owner Author

thlorenz commented Feb 7, 2017

So I fixed the nits pointed out by Trevor, but still need some clarification from @Fishrock123 for some of the above.

TTYWRAP(6) -> Timeout(4) -> TIMERWRAP(5) -> TickObject(3) -> root(1)
```

The `TCPWRAP` isn't part of this graph; evne though it was the reason for

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/evne/even/

```js
const async_hooks = require('async_hooks');

// Return the id of the current execution context.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably worth defining 'execution context' somewhere.

hostname is actually synchronous, but to maintain a completely asynchronous API
the user's callback is placed in a `process.nextTick()`.

The graph only shows **when** a resource was created. Not **why**. So to track

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not why. So to track the why use triggerId.

This is a bit awkward

event
* Returns {AsyncEvent} A reference to `asyncHook`.

Example usage:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems less like an embedder's use but an APM/wrapper's use. I'd think that the embedder would put the emitBefore and emitAfterinsidefunction this.db.getnot thegetInfo` wrapper?

@thlorenz
Copy link
Owner Author

@brycebaril let's continue discussion here: nodejs#12953

const async_hooks = require('async_hooks');

// Return new unique id for a constructing handle.
const id = async_hooks.newUid();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be newId()?

@thlorenz thlorenz closed this Oct 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants