I'm trying to make non-blocking calls to 3 public APIs, i.e website A,B,C and then forward the results back to the rails app as JSON datas. I asked if this is possible in node.js on another forum and it seems it is and someone pointed me to this solution that involves using node.js Step module and async library:
Step(
// Make 3 async calls in parallel
function loadStuff() {
getResultFromSiteA(params1, this.parallel());
getResultFromSiteB(params2, this.parallel());
getResultFromSiteC(params3, this.parallel());
},
// Pass the result to Rails when you're done
function passOntoRails(err, resultsA, resultsB, resultsC) {
if (err) { throw err; }
passResultsToRails(resultsA, resultsB, resultsC);
}
)
Recently I also found similar question here. The answer suggests using forkjoin operator available within js extension I've never heard of; 'reactive js'.
So from what I can understand there's 2 ways of doing this; the first one through node.js and the second way is through simple multiple asynchronous ajax calls from client side using 'reactive'.
I'd like to know if one way simply performs better/faster than another? thanks. any opinions/answers/suggestions would be appreciated.