I have a function for send GET http request with request package. This works good.
//file1.js
var request = require('request');
methods.testcall = function(callback){
request(url, function (error, response, body) {
if (!error && response.statusCode == 200) {
callback(body)
}
if(!error && response.statusCode == 429){ // Rate limit.., try again 1s
setTimeout(this(callback), 1000);
}
})
};
In the next file, i call this function two times. I think the 2 request can run in one time. So when the request is arrive then i call the callback function. In the log i see the result. But, where u see my comment, there i want to wait for ALL testcall(), because i want to be sure in all data arrived to my server.
//file2.js
test.methods.testcall(function(response){
console.log(response)
});
test.methods.testcall(function(response){
console.log(response)
});
// Here, i want to wait for all testcall function.
// When all testcall function sent response
// Im ready to do smtng :)
How can i wait this two method there? Thanks so much!