Created
October 16, 2010 16:02
-
-
Save pgte/629960 to your computer and use it in GitHub Desktop.
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 db1 = initialize_connection_1(); | |
var db2 = initialize_connection_2(); | |
http.createServer(function (request, response) { | |
var all_results = []; | |
var replied = false; | |
var try_reply = function(result, force) { | |
all_results.push(result); | |
if (!replied && (all_results.length == 2 || force)) { | |
replied = true; | |
response.end(render(all_results)); | |
clearTimeout(timeout); | |
} | |
} | |
var timeout = setTimeout(function() { | |
try_reply(null, true); | |
}, 500); | |
db1.query('select * from transactions where ...', function(results) { | |
try_reply(results); | |
}); | |
db2.query('select * from profiles where ...', function(results) { | |
try_reply(results); | |
}); | |
}).listen(8124); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment