Munzy
Active Member
Alright, so I am new to nodejs from php. As most know, php being linear/blocking made coding *easy* per-say. However, I have found myself loving nodejs, and I am having a hard time wrapping my mind around how to let a nodejs function run async, but then wait for responses of that async function before continuing.
Here is some example code
var ping = require("ping");
var verHosts = [
'192.168.230.118',
'192.168.230.25'
];
var verStatus = 0;
verHosts.forEach(function(host) {
ping.sys.probe(host, function(isAlive){
if(isAlive == true) {
verStatus++;
}
})
});
console.log(Date() + " " + "Verified status is at: " + verStatus);
if(verStatus > 0) { // continue shiz and giggles here after I get the above};
If you could elaborate as I am trying to learn as well, not just copy paste in dummy mode!
Thanks!
Here is some example code
var ping = require("ping");
var verHosts = [
'192.168.230.118',
'192.168.230.25'
];
var verStatus = 0;
verHosts.forEach(function(host) {
ping.sys.probe(host, function(isAlive){
if(isAlive == true) {
verStatus++;
}
})
});
console.log(Date() + " " + "Verified status is at: " + verStatus);
if(verStatus > 0) { // continue shiz and giggles here after I get the above};
If you could elaborate as I am trying to learn as well, not just copy paste in dummy mode!
Thanks!
Last edited by a moderator: