1
Well I am doing a function to check certain iteration and if it passes x I pause the contactor, however it is not working, it continues to appear Alert window, follow my example below?
function verificaComplet(tam, page){
var tentativas = 0,
maxRange = tam + 5,
time;
console.log("max Range " + maxRange);
console.log("iteracoes " + iteracoes);
iteracoes = iteracoes + 1;
if(maxRange > iteracoes){
if(w_variavel == tam){
activate_page(page);
desbloqueiTela("#BloqueiaLogin");
}else{
time = setTimeout(function () { verificaComplet(tam, page);}, 5000);
}
}else{
clearTimeout(time);
desbloqueiTela("#BloqueiaLogin");
alert("Tempo de espera escedido, Por favor tente novamente mais tarde.");
}
}
The output of the program is as follows:
max Range 22 VM2450 main.js:608
iteracoes 17 VM2450 main.js:609
max Range 22 VM2450 main.js:608
iteracoes 18 VM2450 main.js:609
max Range 22 VM2450 main.js:608
iteracoes 19 VM2450 main.js:609
max Range 22 VM2450 main.js:608
iteracoes 20 VM2450 main.js:609
max Range 22 VM2450 main.js:608
iteracoes 21 VM2450 main.js:609
max Range 22 VM2450 main.js:608
iteracoes 22 VM2450 main.js:609
max Range 22 VM2450 main.js:608
iteracoes 23 VM2450 main.js:609
max Range 22 VM2450 main.js:608
iteracoes 24 VM2450 main.js:609
max Range 22 VM2450 main.js:608
iteracoes 25 VM2450 main.js:609
max Range 22 VM2450 main.js:608
iteracoes 26 VM2450 main.js:609
max Range 22 VM2450 main.js:608
iteracoes 27 VM2450 main.js:609
max Range 22 VM2450 main.js:608
iteracoes 28 VM2450 main.js:609
max Range 22 VM2450 main.js:608
iteracoes 29 VM2450 main.js:609
max Range 22 VM2450 main.js:608
iteracoes 30 VM2450 main.js:609
max Range 22 VM2450 main.js:608
iteracoes 31 VM2450 main.js:609
max Range 22 VM2450 main.js:608
iteracoes 32 VM2450 main.js:609
max Range 22 VM2450 main.js:608
iteracoes 33 VM2450 main.js:609
max Range 22 VM2450 main.js:608
iteracoes 34 VM2450 main.js:609
max Range 22 VM2450 main.js:608
iteracoes 35 VM2450 main.js:609
max Range 22 VM2450 main.js:608
iteracoes 36 VM2450 main.js:609
max Range 22 VM2450 main.js:608
iteracoes 37 VM2450 main.js:609
could post the method code
desbloqueiTela
? the only explanation I see for this loop, is thedesbloqueiTela
is calling theverificaComplet
– Tobias Mesquita
you could add the following line in the function
verificaComplet
:console.log("caller " + (arguments.callee.caller.name || "desconhecido"));
– Tobias Mesquita
P.S: if using
strict mode
useverificaComplet.caller.name || "desconhecido"
in place ofarguments.callee
– Tobias Mesquita
Another possibility is some method to change the value of [ iterations ], which is an external scope variable. And there’s also the variable [ w_variable ] which is also external-scoped.
– Moykn
P.S.: I got it to work on this Fiddle: https://jsfiddle.net/kb7s8eeq/ And one more thing. The clearTimeout you call has no use. The [ time ] variable is declared in every call to the function. So when you call clearTimeout(time) the value of time is Undefined. And setTimeout runs only once. The setInterval is executed continuously. Consider the conditions for your function to act correctly: maxRange must be greater than iterations w_variable must be equal to tam Both conditions are evaluated as "false".
– Moykn
Mokyn will test here in production to see if it will work
– Renan Rodrigues
Guys I managed to solve... The problem was because I had a speaker who made the call to the function, but now everything worked well.
– Renan Rodrigues