Skip to content

Instantly share code, notes, and snippets.

@listochkin
Forked from iliakan/domain.js
Last active December 21, 2015 15:29
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save listochkin/6327396 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)
console.log(requestDomain === domain.active && requestDomain !== null);
connection.query('SELECT 1', function(err, rows) {
console.log(requestDomain === domain.active && requestDomain !== null);
throw new Error("BOOM!")
});
});
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment