Skip to content

Instantly share code, notes, and snippets.

@iliakan
Created August 24, 2013 10:43
Show Gist options
  • Save iliakan/6327393 to your computer and use it in GitHub Desktop.
Save iliakan/6327393 to your computer and use it in GitHub Desktop.
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',
});
var requestDomain = domain.create();
requestDomain.on("error", function(err) {
console.log("DOMAIN: %s", err);
});
pool.getConnection(function(err, connection) {
connection.end();
AND_HERE_WE_GO({}, {});
})
function AND_HERE_WE_GO(req, res) {
requestDomain.run(function() {
pool.getConnection(function(err, connection) {
// connected! (unless `err` is set)
connection.query('SELECT 1', function(err, rows) {
throw new Error("BOOM!")
});
});
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment