Skip to content

Instantly share code, notes, and snippets.

@travisperson
Created June 24, 2011 04:31
Show Gist options
  • Save travisperson/1044226 to your computer and use it in GitHub Desktop.
Save travisperson/1044226 to your computer and use it in GitHub Desktop.
Simple express no blocking test
var app = require('express').createServer();
var Client = require('mysql').Client,
db = new Client();
db.user = 'root';
db.password = '';
db.connect();
app.get('/', function(req, res){
console.log("Request to /");
db.query('SELECT RAND() AS s', function(err, results) {
var r_size = Math.round(results[0].s*10);
var i = 0;
for(i=r_size;i>=0;i--)
{ console.log("Set: "+i);
db.query('SELECT SLEEP(1)', function(err, results) {
r_size--;
console.log("R_size: "+r_size);
if(r_size == 0)
{ console.log("Sending...");
res.send('Hello!');
}
});
console.log("Set: "+ i +" | No Block");
}
});
console.log("Request to / | No Block");
});
app.get('/ping', function(req, res){
console.log("Request to /ping");
res.send('pong');
console.log("Request to /ping | No Block");
});
app.listen(7070);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment