Js sample for setTimeout
<!DOCTYPE html>
See console, sample code to use setTimeout for a fixed number of iterations. Can use to do parts of work with async behaviour, if can break up task.
<script>
nxt (0, 0);
function nxt(num, itertn){
console.log(num, itertn);
if(num < 4){
if(itertn <= 3){
if(itertn == 3){
num++;
}
itertn++;
}else{
console.log("itertn 0; ", num, itertn);
itertn = 0;
}
setTimeout(nxt, 1000, num, itertn);
}else{
console.log("rtn ", num, itertn);
return;
}
}
</script>
- Log in to post comments