Skip to content

Commit 1a3e496

Browse files
committed
docs: minor corrections to AsyncWrap
1 parent 7313cfe commit 1a3e496

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

docs/AsyncWrap/README.md

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ socket.connect(req, address, port);
5555
socket.destroy();
5656
```
5757

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.
6060

6161
`TCPConnectWrap` gets its information by setting properties on the handle
6262
object, like `address` and `port`. Those properties are read by the C++ layer,
6363
but can also be inspected from the AsyncWrap hooks. When the handle is created
6464
using `new TCPConnectWrap()` the `init` hook is called.
6565

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
6767
connection is made or failed. Just before calling `oncomplete` the `pre` hook
6868
is called, just after the `post` hook is called.
6969

@@ -72,10 +72,10 @@ is passed as arguments to a method `.connect` and the `onread` function
7272
is called multiple times, thus it behaves like an event. This also means that
7373
the `pre` and `post` hooks are called multiple times.
7474

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.
7979

8080
Thus one should expect the hooks be called in the following order:
8181

@@ -152,10 +152,9 @@ asyncWrap.disable();
152152

153153
#### The Hooks
154154

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.
159158

160159
```javascript
161160
function init(provider, uid, parent) { }
@@ -168,18 +167,18 @@ function destroy(uid) { }
168167

169168
In the `init`, `pre` and `post` cases the `this` variable is the handle object.
170169
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.
172171

173172
In the `init` hook the handle object is not yet fully constructed, thus some
174173
properties are not safe to read. This causes problems when doing
175174
`util.inspect(this)` or similar.
176175

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.
179178

180179
##### provider
181180

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`
183182
object map.
184183

185184
At the time of writing this is the current list:
@@ -308,12 +307,12 @@ for how to do it.
308307

309308
## Resources
310309

310+
* Status overview of AsyncWrap: https://github.com/nodejs/tracing-wg/issues/29
311311
* An intro to AsyncWrap by Trevor Norris: http://blog.trevnorris.com/2015/02/asyncwrap-tutorial-introduction.html (outdated)
312312
* Slides from a local talk Andreas Madsen did on AsyncWrap:
313313
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).
315314
* 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
317316

318317
----
319318

0 commit comments

Comments
 (0)