Skip to content
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: correct tracingChannel.traceCallback() #51068

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions doc/api/diagnostics_channel.md
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ channels.tracePromise(async () => {
});
```

#### `tracingChannel.traceCallback(fn[, position[, context[, thisArg[, ...args]]]])`
#### `tracingChannel.traceCallback(fn, position, context, thisArg, ...args)`

<!-- YAML
added:
Expand All @@ -874,23 +874,23 @@ added:

* `fn` {Function} callback using function to wrap a trace around
* `position` {number} Zero-indexed argument position of expected callback
* `context` {Object} Shared object to correlate trace events through
(defaults to last argument if `undefined` is passed)
* `context` {Object} Shared object to correlate trace events through (defaults
to `{}` if `undefined` is passed)
* `thisArg` {any} The receiver to be used for the function call
* `...args` {any} Optional arguments to pass to the function
* `...args` {any} arguments to pass to the function (must include the callback)
* Returns: {any} The return value of the given function

Trace a callback-receiving function call. This will always produce a
Trace a callback-receiving function call. The callback is expected to follow
the error as first arg convention typically used. This will always produce a
[`start` event][] and [`end` event][] around the synchronous portion of the
function execution, and will produce a [`asyncStart` event][] and
[`asyncEnd` event][] around the callback execution. It may also produce an
[`error` event][] if the given function throws an error or the returned
promise rejects. This will run the given function using
[`error` event][] if the given function throws or the first argument passed to
the calblack is set. This will run the given function using
Flarna marked this conversation as resolved.
Show resolved Hide resolved
[`channel.runStores(context, ...)`][] on the `start` channel which ensures all
events should have any bound stores set to match this trace context.

The `position` will be -1 by default to indicate the final argument should
be used as the callback.

```mjs
import diagnostics_channel from 'node:diagnostics_channel';

Expand Down
4 changes: 1 addition & 3 deletions lib/diagnostics_channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,7 @@ class TracingChannel {
// Using runStores here enables manual context failure recovery
asyncStart.runStores(context, () => {
try {
if (callback) {
return ReflectApply(callback, this, arguments);
}
return ReflectApply(callback, this, arguments);
} finally {
asyncEnd.publish(context);
}
Expand Down
Loading