Skip to content

Instantly share code, notes, and snippets.

@pgte
Created October 16, 2010 16:02
Show Gist options
  • Save pgte/629960 to your computer and use it in GitHub Desktop.
Save pgte/629960 to your computer and use it in GitHub Desktop.
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