@@ -55,15 +55,15 @@ socket.connect(req, address, port);
55
55
socket .destroy ();
56
56
```
57
57
58
- The first one (` TCPConnectWrap ` ) is for connecting the socket, the second
59
- one (` TCP ` ) is for maintaining the connection.
58
+ The first handle object (` TCPConnectWrap ` ) is for connecting the socket, the
59
+ second one (` TCP ` ) is for maintaining the connection.
60
60
61
61
` TCPConnectWrap ` gets its information by setting properties on the handle
62
62
object, like ` address ` and ` port ` . Those properties are read by the C++ layer,
63
63
but can also be inspected from the AsyncWrap hooks. When the handle is created
64
64
using ` new TCPConnectWrap() ` the ` init ` hook is called.
65
65
66
- A ` oncomplete ` property is also set, this is the callback for when the
66
+ An ` oncomplete ` property is also set, this is the callback for when the
67
67
connection is made or failed. Just before calling ` oncomplete ` the ` pre ` hook
68
68
is called, just after the ` post ` hook is called.
69
69
@@ -72,10 +72,10 @@ is passed as arguments to a method `.connect` and the `onread` function
72
72
is called multiple times, thus it behaves like an event. This also means that
73
73
the ` pre ` and ` post ` hooks are called multiple times.
74
74
75
- At some time later in the lifetime of the program ` socket.destroy() ` is called,
76
- this will call the ` destroy ` hook for the ` socket ` handle. Other handle objects
77
- aren't directly destroyed, in that case the ` destroy ` hook is called when the
78
- handle object garbage collected by v8.
75
+ At some later time the ` socket.destroy() ` is called, this will call the
76
+ ` destroy ` hook for the ` socket ` handle. Other handle objects aren't explicitly
77
+ destroyed, in that case the ` destroy ` hook is called when the handle object is
78
+ garbage collected by v8.
79
79
80
80
Thus one should expect the hooks be called in the following order:
81
81
@@ -152,10 +152,9 @@ asyncWrap.disable();
152
152
153
153
#### The Hooks
154
154
155
- Currently there are 4 hooks: ` init ` , ` pre ` , ` post ` ` destroy ` . The function
156
- signatures are quite similar. The ` this ` variable refers to the handle object.
157
- The ` init ` hook has three extra arguments ` provider ` , ` uid ` and ` parent ` . The
158
- ` destroy ` hook also has the ` uid ` argument.
155
+ Currently there are 4 hooks: ` init ` , ` pre ` , ` post ` ` destroy ` . The ` this `
156
+ variable refers to the handle object. The ` init ` hook has three extra arguments
157
+ ` provider ` , ` uid ` and ` parent ` . The ` destroy ` hook also has the ` uid ` argument.
159
158
160
159
``` javascript
161
160
function init (provider , uid , parent ) { }
@@ -168,18 +167,18 @@ function destroy(uid) { }
168
167
169
168
In the ` init ` , ` pre ` and ` post ` cases the ` this ` variable is the handle object.
170
169
Users may read properties from this object such as ` port ` and ` address ` in the
171
- ` TCPConnectWrap ` case, or set user specific properties
170
+ ` TCPConnectWrap ` case, or set user specific properties.
172
171
173
172
In the ` init ` hook the handle object is not yet fully constructed, thus some
174
173
properties are not safe to read. This causes problems when doing
175
174
` util.inspect(this) ` or similar.
176
175
177
- In the ` destroy ` hook ` this ` equals ` null ` , this is because the handle objects
178
- has been deleted by the garbage collector and thus doesn't exists.
176
+ In the ` destroy ` hook ` this ` is ` null ` , this is because the handle objects has
177
+ been deleted by the garbage collector and thus doesn't exists.
179
178
180
179
##### provider
181
180
182
- This is an integer that refer to names defined in an ` asyncWrap.Providers `
181
+ This is an integer that refer to names defined in the ` asyncWrap.Providers `
183
182
object map.
184
183
185
184
At the time of writing this is the current list:
@@ -308,12 +307,12 @@ for how to do it.
308
307
309
308
## Resources
310
309
310
+ * Status overview of AsyncWrap: https://github.com/nodejs/tracing-wg/issues/29
311
311
* An intro to AsyncWrap by Trevor Norris: http://blog.trevnorris.com/2015/02/asyncwrap-tutorial-introduction.html (outdated)
312
312
* Slides from a local talk Andreas Madsen did on AsyncWrap:
313
313
https://github.com/AndreasMadsen/talk-async-wrap (outdated)
314
- * There was also some discussion in [ issue #21 ] ( https://github.com/nodejs/tracing-wg/issues/21#issuecomment-142727693 ) .
315
314
* Complete (hopefully) long-stack-trace module that uses AsyncWrap: https://github.com/AndreasMadsen/trace
316
- * Visualization tool for AsyncWrap wrap : https://github.com/AndreasMadsen/dprof
315
+ * Visualization tool for AsyncWrap: https://github.com/AndreasMadsen/dprof
317
316
318
317
----
319
318
0 commit comments