please help!
How to breaking if available true?
I use node js tcp-ping module.
My code
var tcpp = require('tcp-ping');
let arr = ['imap:143', 'imap:993', 'mail:143', 'mail:993'];
for (let i = 0; i < arr.length; ++i) {
let alias = arr[i].split(":")[0];
let port = arr[i].split(":")[1];
tcpp.probe(alias+'.aol.com', parseInt(port), function(err, available) {
if(available){
//need break
}
});
}
forloop has already finished LONG before your asynchronous callback gets called. So, you can't use this type of structure if you really want to stop theforloop based on anasynchronous result. To understand how this works, yourfor` loop runs to completion calling all thetcpp.probe()functions. Then, sometime later, long after theforloop has finished, the callbacks you passed totcpp.probe()will start getting called. To help you with a solution that could work, we need to know what you're really trying to accomplish here.