Created
August 24, 2013 10:58
-
-
Save iliakan/6327476 to your computer and use it in GitHub Desktop.
This file contains 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 EE = require('events').EventEmitter; | |
var domain = require('domain'); | |
var mysql = require('mysql'); | |
var pool = mysql.createPool({ | |
host: '127.0.0.1', | |
port: 3306, | |
database: 'test', | |
user: 'localuser', | |
password: 'localpass', | |
}); | |
pool.getConnection(function(err, connection) { | |
connection.end(); | |
AND_HERE_WE_GO(new EE, new EE); | |
}); | |
function AND_HERE_WE_GO(req, res) { | |
var requestDomain = domain.create(); | |
requestDomain.on("error", function(err) { | |
console.log("DOMAIN: %s", err); | |
}); | |
requestDomain.add(req); | |
requestDomain.add(res); | |
requestDomain.run(function() { | |
pool.getConnection(function(err, connection) { | |
// connected! (unless `err` is set) | |
connection.query('SELECT 1', req.domain.intercept(function(rows) { | |
throw new Error("BOOM!") | |
})); | |
}); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment