Created
June 24, 2011 04:31
-
-
Save travisperson/1044226 to your computer and use it in GitHub Desktop.
Simple express no blocking test
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 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