-1
Hello I’m with a doubt I think they could help me, to some problem in running a function twice in the same script
example have this function
exports.getValueMsg = function(){
return new Promise((resolve, reject) => {
pconn.pool.query("SELECT b.numero_serie, b.grupo_msg, b.index_msg, b.valor_msg FROM bor_msg b ", (err, rows) => {
if (!err) {
count = Object.keys(rows).length;
while(i<count){
console.log(i);
dadosMsg = rows.rows[i];
i++;
return resolve(dadosMsg);
}
} else {
reject(err);
console.log(err);
}
});
})
}
and it returns me the query results normally. More when I call this function ex below
const exec = async() => {
try {
var macroLength = await dbMsg.getValueMsg();
var count = Object.keys(macroLength).length;
for(var i=0;i<count;i++){
var valueMsg = await dbMsg.getValueMsg();
console.log(valueMsg);
macro = await xmlTemplates.xml_16_begin(valueMsg);
clientOut.write(macro);
await fc.wait(2200);
clientOut.write(xmlTemplates.xml_16_end());
await fc.wait(3000);
dbMsg.upStatusMsg(statusMsg, valueMsg);
setTimeout(function(){
if(vDataOutObj.Package.Header._attributes.Id == 116){
console.log(vDataOutObj.Package.Header._attributes.Id);
dbMsg.upStatusMsg(statusMsg2, valueMsg);
}
},3100);
}
}catch (error) {
console.log(error);
}
}
it returns me duplicated results and can not go through the loop fully, I think it is because I am running the function twice...so it duplicates the results and does not return me all.. but if I don’t perform the function getValueMsg() twice, as I will decide how far my For must travel