@@ -117,10 +117,10 @@ if it's just patch update._
117117To assign the hooks call:
118118
119119``` javascript
120- asyncWrap .setupHooks (init, pre, post, destroy);
120+ asyncWrap .setupHooks ({ init, pre, post, destroy} );
121121function init (uid , provider , parentUid , parentHandle ) { /* consumer code */ }
122122function pre (uid ) { /* consumer code */ }
123- function post (uid ) { /* consumer code */ }
123+ function post (uid , didThrow ) { /* consumer code */ }
124124function destroy (uid ) { /* consumer code */ }
125125```
126126
@@ -153,13 +153,14 @@ asyncWrap.disable();
153153#### The Hooks
154154
155155Currently 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
160161function init (uid , provider , parentUid , parentHandle ) { }
161162function pre (uid ) { }
162- function post (uid ) { }
163+ function post (uid , didThrow ) { }
163164function destroy (uid ) { }
164165```
165166
@@ -245,14 +246,19 @@ handle was created using the `pre` and `post` hooks. However the
245246
246247This 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
250256A classic use case for AsyncWrap is to create a long-stack-trace tool.
251257
252258``` javascript
253259const asyncWrap = process .binding (' async_wrap' );
254260
255- asyncWrap .setupHooks (init, before, after , destroy);
261+ asyncWrap .setupHooks ({ init, pre, post , destroy} );
256262asyncWrap .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.
0 commit comments