Skip to content

Commit 2650b32

Browse files
committed
Merge pull request #45 from AndreasMadsen/async-wrap-update-pr-5756
docs: update after nodejs/node#5756
2 parents bdc667d + 6ee1140 commit 2650b32

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

docs/AsyncWrap/README.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ if it's just patch update._
117117
To assign the hooks call:
118118

119119
```javascript
120-
asyncWrap.setupHooks(init, pre, post, destroy);
120+
asyncWrap.setupHooks({init, pre, post, destroy});
121121
function init(uid, provider, parentUid, parentHandle) { /* consumer code */ }
122122
function pre(uid) { /* consumer code */ }
123-
function post(uid) { /* consumer code */ }
123+
function post(uid, didThrow) { /* consumer code */ }
124124
function destroy(uid) { /* consumer code */ }
125125
```
126126

@@ -153,13 +153,14 @@ asyncWrap.disable();
153153
#### The Hooks
154154

155155
Currently there are 4 hooks: `init`, `pre`, `post` `destroy`. The `this`
156-
variable refers to the handle object, they all have a `uid` argument, finally
156+
variable refers to the handle object, they all have a `uid` argument. `post`
157+
provides information about the execution of the callback. Finally
157158
`init` provides extra information about the creation of the handle object.
158159

159160
```javascript
160161
function init(uid, provider, parentUid, parentHandle) { }
161162
function pre(uid) { }
162-
function post(uid) { }
163+
function post(uid, didThrow) { }
163164
function destroy(uid) { }
164165
```
165166

@@ -245,14 +246,19 @@ handle was created using the `pre` and `post` hooks. However the
245246

246247
This is similar to parentUid but is the actual parent handle object.
247248

249+
##### didThrow
250+
251+
If the callback threw, but the process was allowed to continue due to either
252+
`uncaughtException` or the `domain` module, then `didThrow` will be true.
253+
248254
## Example
249255

250256
A classic use case for AsyncWrap is to create a long-stack-trace tool.
251257

252258
```javascript
253259
const asyncWrap = process.binding('async_wrap');
254260

255-
asyncWrap.setupHooks(init, before, after, destroy);
261+
asyncWrap.setupHooks({init, pre, post, destroy});
256262
asyncWrap.enable();
257263

258264
// global state variable, that contains the stack traces and the current uid
@@ -270,13 +276,13 @@ function init(uid, provider, parentUid, parentHandle) {
270276
const extraStack = stack.get(parentUid || currentUid);
271277
stack.set(uid, localStack + '\n' + extraStack);
272278
}
273-
function before(uid) {
279+
function pre(uid) {
274280
// A callback is about to be called, update the `currentUid` such that
275281
// it is correct for when another handle is initialized or `getStack` is
276282
// called.
277283
currentUid = uid;
278284
}
279-
function after(uid) {
285+
function post(uid, didThrow) {
280286
// At the time of writing there are some odd cases where there is no handle
281287
// context, this line prevents that from resulting in wrong stack trace. But
282288
// the stack trace will be shorter compared to what ideally should happen.

docs/AsyncWrap/example-trace/trace.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const asyncWrap = process.binding('async_wrap');
44

5-
asyncWrap.setupHooks(init, before, after, destroy);
5+
asyncWrap.setupHooks({init, pre, post, destroy});
66
asyncWrap.enable();
77

88
// global state variable, that contains the stack traces and the current uid
@@ -20,13 +20,13 @@ function init(uid, provider, parentUid, parentHandle) {
2020
const extraStack = stack.get(parentUid || currentUid);
2121
stack.set(uid, localStack + '\n' + extraStack);
2222
}
23-
function before(uid) {
23+
function pre(uid) {
2424
// A callback is about to be called, update the `currentUid` such that
2525
// it is correct for when another handle is initialized or `getStack` is
2626
// called.
2727
currentUid = uid;
2828
}
29-
function after(uid) {
29+
function post(uid, didThrow) {
3030
// At the time of writing there are some odd cases where there is no handle
3131
// context, this line prevents that from resulting in wrong stack trace. But
3232
// the stack trace will be shorter compared to what ideally should happen.

0 commit comments

Comments
 (0)