I am new to node and having some headaches with async programming. I have a simple script pinging devices on my network. Now I want to build the following: if one of the devices is on the network then how do I handle the callback so that the decision is only made once all the pings are terminated?
var exec = require('child_process').exec;
function doThePing(ipaddy){
exec("ping " + ipaddy, puts);
}
function puts(error, stdout, stderr) {
console.log(stdout);
if (error !== null){
console.log("error!!!!");
}
else{
console.log("found device!")
}
}
function timeoutFunc() {
doThePing("192.168....");
doThePing("192.168....");
//if all pings are successful then do..
setTimeout(timeoutFunc, 15000);
}
timeoutFunc();