Last active
August 29, 2015 13:57
-
-
Save Jimbly/9379878 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var domain = require('domain'); | |
| var assert = require('assert'); | |
| var DELAY = 10; | |
| function doerr() { | |
| var fired = false; | |
| setTimeout(function () { | |
| fired = true; | |
| throw "Handled error"; | |
| }, DELAY); | |
| setTimeout(function () { | |
| if (!fired) { | |
| console.log('Test failed'); | |
| } | |
| }, DELAY + 1000); | |
| } | |
| function withoutDomains(do_final) { | |
| var next; | |
| process.on('uncaughtException', function (err) { | |
| console.log('uncaughtException: ' + err); | |
| next(); | |
| }); | |
| doerr(); | |
| next = function () { | |
| doerr(); | |
| next = function () { | |
| process.removeAllListeners('uncaughtException'); | |
| do_final(); | |
| }; | |
| }; | |
| } | |
| function withDomains() { | |
| var next; | |
| function asyncError() { | |
| var d = domain.create(); | |
| d.on('error', function (err) { | |
| console.log('asyncError: ' + err); | |
| d.dispose(); | |
| next(); | |
| }); | |
| d.run(doerr); | |
| } | |
| asyncError(); | |
| next = function () { | |
| asyncError(); | |
| next = function () { | |
| console.log('Test passed.'); | |
| }; | |
| }; | |
| } | |
| withoutDomains(function () { | |
| withDomains(); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment