Skip to content

Instantly share code, notes, and snippets.

@brigand
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brigand/2c653c3a378a8d759b15 to your computer and use it in GitHub Desktop.
Save brigand/2c653c3a378a8d759b15 to your computer and use it in GitHub Desktop.
var mysql = require('mysql'),
http = require('http');
var connections = [null, null, null].map(function(){
var connection = mysql.createConnection({
host : 'localhost',
database : 'benchmark',
user : 'root',
password : '1234'
});
connection.connect();
return connection;
});
http.createServer(function(req, res){
var state = {
foo: false,
bar: false,
baz: false
};
var done = function( tbl ){
state[ tbl ] = true;
if( state.foo && state.bar && state.baz ){
res.end('OK');
}
};
connections[0].query('SELECT * FROM foo', function(err, rows, fields) {
done('foo');
});
connections[1].query('SELECT * FROM bar', function(err, rows, fields) {
done('bar');
});
connections[2].query('SELECT * FROM baz', function(err, rows, fields) {
done('baz');
});
}).listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment