Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
domain: document and test dispose event
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasMadsen authored and bnoordhuis committed Jun 9, 2012
1 parent 535e109 commit 60b45dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions doc/api/domain.markdown
Expand Up @@ -258,6 +258,8 @@ The intention of calling `dispose` is generally to prevent cascading
errors when a critical part of the Domain context is found to be in an
error state.

Once the domain is disposed the `dispose` event will emit.

Note that IO might still be performed. However, to the highest degree
possible, once a domain is disposed, further errors from the emitters in
that set will be ignored. So, even if some remaining actions are still
Expand Down
8 changes: 7 additions & 1 deletion test/simple/test-domain-http-server.js
Expand Up @@ -28,7 +28,8 @@ var objects = { foo: 'bar', baz: {}, num: 42, arr: [1,2,3] };
objects.baz.asdf = objects;

var serverCaught = 0;
var clientCaught = 0
var clientCaught = 0;
var disposeEmit = 0;

var server = http.createServer(function(req, res) {
var dom = domain.create();
Expand Down Expand Up @@ -84,6 +85,10 @@ function next() {
dom.dispose();
});

dom.on('dispose', function() {
disposeEmit += 1;
});

var req = http.get({ host: 'localhost', port: common.PORT, path: p });
dom.add(req);
req.on('response', function(res) {
Expand Down Expand Up @@ -111,5 +116,6 @@ function next() {
process.on('exit', function() {
assert.equal(serverCaught, 2);
assert.equal(clientCaught, 2);
assert.equal(disposeEmit, 2);
console.log('ok');
});

0 comments on commit 60b45dc

Please sign in to comment.