this is my first stackoverflow post. In this NodeJS app, the objective is to get the max value of memory avaible from a IP's pool. I know that I can use the function obtainMemory with a callback but idk how to use in this scenario.
decide(){
for(var i=0;i < raspberrys.length;i++ ){
let ip = raspberrys[i];
let freeSpace = this.obtainMemory(ip);
console.log(freeSpace);
}
},obtainMemory(ip){
https.get('http://'+ip+':3030/memory', (response)=>{
let data='';
response.on('data', (chunk) =>{
data+=chunk;
});
response.on('end',()=>{
let obj = JSON.parse(data);
console.log(obj.free );
return obj.free;
})
}).on('error',(error)=>{
console.log(error);
});
}
For example if i have 2 raspberrys with 2GB and 1MB, I have to return the IP of the first raspberry. Thanks.