Let's imagine the following code:
function FazAlgoTrabalhoso(parametro1, parametro2, parametro3){
//Algo trabalhoso aqui
}
var i;
for(i=0;i<=coisas.length;i++){
//"coisas" é um array já preenchido
FazAlgoTrabalhoso(coisas[i].algo1, coisas[i].algo2, coisas[i].algo3);
}
$( "#botao_para_cancelar" ).click(function() {
//Algo para cancelar...
});
- Let's say that the "things" array has 100 positions, so the for loop run 100 times, that is, it will do "something laborious" 100 times.
- Let's also consider that "WorkLoad" takes about 5 seconds to run completely.
My question is: How do I manage the cancellation of "WorkOnLine"? For example, if it has already run 50 times, how can I cancel the subsequent executions through a button? I did not succeed in my attempts and it always ends up running the whole loop ....