i have not been able to figure out asynchronous flow in nodejs for the life of me. i am currently trying to get a response from a server. which is no problem. and use that response to validate whether to add the statement to an array if true. and to ignore if false. currently this is what im using for testing. and in the log i have one statement with a response of false and one with true. but both are using the same address.
var test = Object.keys(addressAmounts);
test.forEach(function(address) {
daemon.cmd('validateaddress', [address], function (results) {
var validWorkerAddress = results[0].response.isvalid;
//if (validWorkerAddress != "false") {
//console.log("\n\n\n\n Worker: " + w + " GETS COINS! " + coin + "\n\n\n");
//} else {
//console.log("\n\n\n\n Worker: " + w + " NO COINS BRA! " + coin + "\n\n\n");
//}
//console.log("Test for " + w + " is " + results[0].response.isvalid);
if (validWorkerAddress != 'false') {
console.log("Test for " + address + " was ok on " + coin +' isvalid:'+ validWorkerAddress + "\n\n\n");
} else {
console.log("Test for " + address + " was NOT ok\n\n\n");
}
});
});