-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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: fix nits in code examples of async_hooks.md #13400
Conversation
I am unsure about 2 fragments if there are typos there:
Let me know if these are to be addressed too. |
fs.open(path, (err, fd) => { | ||
console.log(async_hooks.currentId()); // 2 - open() | ||
fs.open(path, 'r', (err, fd) => { | ||
console.log(async_hooks.currentId()); // 6 - open() |
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.
Yeah, something is wrong with the async_hooks.currentId()
this is supposed to be 2
.
edit: oh, it might be because of console.log
. Then 6
is likely correct.
doc/api/async_hooks.md
Outdated
|
||
let indent = 0; | ||
async_hooks.createHook({ | ||
init(asyncId, type, triggerId) { | ||
const cId = async_hooks.currentId(); | ||
fs.writeSync(1, ' '.repeat(indent) + `${type}(${asyncId}): ` + | ||
fs.writeSync(1, `${' '.repeat(indent)}${type}(${asyncId}): ` + |
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.
I don't care. But for me, this is not more readable than the original.
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.
FWIW, for me, mixing template literals with string concatenation seems a bit confusing. However, if there are some -1, I can revert.
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.
FWIW You know I like it when you assign expressions to const
s, make it "less operations per line"
But if not I'm +1 for homogeneous templates vs. templates + contacts
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.
And now I see it's used for all hooks, so +4 on const indentString = ' '.repeat(indent)
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.
I agree with @AndreasMadsen , the previous version was more readable in my eyes.
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.
I think it is the lack of separation between formatting (' '.repeat(indent)
) and information (${type}(${asyncId}
). Maybe if ${indentString} ${type}(${asyncId}):
is used we get the best of both worlds.
No, task it correct. Although "purpose" might be a better word.
Yes, those are good suggestions. |
New linter CI after rewording and fixing a typo: https://ci.nodejs.org/job/node-test-linter/9553/ |
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.
Nits
doc/api/async_hooks.md
Outdated
@@ -221,12 +221,13 @@ The following is a simple demonstration of `triggerId`: | |||
|
|||
```js | |||
const async_hooks = require('async_hooks'); |
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.
I say remove both, snippets don't have to be complete, so this is cruft.
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.
Well, they need not, but many readers will test the snippets, so I prefer to be consistent towards completeness, not implying (RE: empathy :)
doc/api/async_hooks.md
Outdated
@@ -272,24 +273,25 @@ elaborate to make calling context easier to see. | |||
|
|||
```js | |||
const async_hooks = require('async_hooks'); |
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.
ditto
doc/api/async_hooks.md
Outdated
|
||
let indent = 0; | ||
async_hooks.createHook({ | ||
init(asyncId, type, triggerId) { | ||
const cId = async_hooks.currentId(); | ||
fs.writeSync(1, ' '.repeat(indent) + `${type}(${asyncId}): ` + | ||
fs.writeSync(1, `${' '.repeat(indent)}${type}(${asyncId}): ` + |
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.
FWIW You know I like it when you assign expressions to const
s, make it "less operations per line"
But if not I'm +1 for homogeneous templates vs. templates + contacts
doc/api/async_hooks.md
Outdated
|
||
let indent = 0; | ||
async_hooks.createHook({ | ||
init(asyncId, type, triggerId) { | ||
const cId = async_hooks.currentId(); | ||
fs.writeSync(1, ' '.repeat(indent) + `${type}(${asyncId}): ` + | ||
fs.writeSync(1, `${' '.repeat(indent)}${type}(${asyncId}): ` + |
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.
And now I see it's used for all hooks, so +4 on const indentString = ' '.repeat(indent)
doc/api/async_hooks.md
Outdated
// of triggerId() is the ID of "conn". | ||
// The resource that caused (or triggered) this callback to be called | ||
// was that of the new connection. Thus the return value of triggerId() | ||
// is the ID of "conn". |
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.
@AndreasMadsen /s/ID/asyncId
/ ?
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.
yes
@@ -462,6 +464,8 @@ will occur and node will abort. | |||
The following is an overview of the `AsyncResource` API. | |||
|
|||
```js | |||
const { AsyncResource } = require('async_hooks'); |
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.
less (because of the destructuring) but still cruft
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.
This is the only place where a reader can find out how to obtain AsyncResource
.
cruft - https://en.wikipedia.org/wiki/Cruft
That sentence is too metaphorical (borderline poetry 😉). I would suggest:
|
About the
|
One more thing. I know a guy who is a big contributor in StackExchange, he always puts tiny mistakes in his snippets so the users will have to understand them in order to fix the problem. |
@refack One nice thing about explicit
One problem that we might not notice much is that much of the Node documentation is written by people with an extensive understanding of how Node works, like everybody in this conversation. I can’t actually tell whether those extra bits of code are helpful, because how to create them is obvious to me even in the case of the destructuring ones, and I suspect the same might be true for you. ;) |
I've tried to address comments: Commit 1: remove 2 Commit 4: add a helper variable to reduce clutter. Commit 6: ID -> asyncId. |
That's a very laudable goal!
Definitely! I agree it's hard to find the right balance. |
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.
I think it's a good balance 💯
Landed in 5d9dc94 |
* Make `require()` consistent. * Add missing argument. * Add missing `\n` in outputs. * Reduce string concatenations. * Update outputs. * Reword and fix a typo. PR-URL: #13400 Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Andreas Madsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
* Make `require()` consistent. * Add missing argument. * Add missing `\n` in outputs. * Reduce string concatenations. * Update outputs. * Reword and fix a typo. PR-URL: #13400 Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Andreas Madsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
Checklist
Affected core subsystem(s)
doc, async_hooks
require()
consistent.\n
in outputs.