You might want to use AJAX, along with jQuery. There's a parameter to make sure it sends synchronous calls instead of the normal asynchronous calls.
It would look something like this:
if(/*condition*/) {
function RPCCall() {
return $.ajax({
type: "GET",
url: remote_url,
async: false
}).responseText;
}
//business logic
}
If you really wouldn't want to use AJAX, and use nodejs you could do something like this:
var sequence = Futures.sequence();
sequence
.then(function(next) {
http.get({}, next);
})
.then(function(next, res) {
res.on("data", next);
})
.then(function(next, d) {
http.get({}, next);
})
.then(function(next, res) {
...
})
If you need to pass along a scope, you could do something like this.
.then(function(next, d) {
http.get({}, function(res) {
next(res, d);
});
})
.then(function(next, res, d) { })
...
})
I hope this will be of some help.