question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JavaScript setTimeout infinite loop without recursion

See original GitHub issue

https://stackoverflow.com/questions/51953379/javascript-settimeout-infinite-loop-without-recursion/52100787

I cannot use Obfuscator.io(https://obfuscator.io/) to uglify my JS script because it contains a setTimeout within a function that calls itself. MCVE:

function repeater() {
    // DO SOME STUFF...
    setTimeout(repeater, 100);
}
repeater();

Custom obfuscation settings required to reproduce:

  • Identifier Names Generator: Mangled
  • Reserved Names: $ - jQuery

Obfuscator.io’s error message:

Error: @postConstruct error in class t: @postConstruct error in class t: Maximum call stack size exceeded

I’ve read a few other Stack Overflow questions about this. I understand that calling setTimeout(func) inside func is not actually recursion.

But still, Obfuscator.io’s algorithm can’t handle a self-invoking setTimeout delay.

How do I make a repeatedly-executing function using setTimeout without calling it in the function itself? I don’t want to use setInterval because I want the delay to begin each time after the function’s code has run. setInterval ignores that.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
sanex3339commented, Nov 28, 2019

@zamotkin Done. Thank you for your fixes!

1reaction
zamotkincommented, Nov 28, 2019

@sanex3339 yes, thank you, I have now a time to help this project.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript setTimeout infinite loop without recursion
How do I make a repeatedly-executing function using setTimeout without calling it in the function itself? I don't want to use setInterval ...
Read more >
Watch Out When Using SetTimeout() in For Loop #JS - Medium
In this case, it will run after for loop finishes. At this point, i is already 5 when the console.log([i]) is about to...
Read more >
The Call Stack is Not an Infinite Resource — How to Avoid a ...
The setTimeout function schedules a function call to be handled by the event loop at some future point in time. True recursion isn't ......
Read more >
Be careful with setTimeout in loops (Example) - Coderwall
Using setTimeout in the example loop will not behave as expected, if you expect that there will be a one second interval between...
Read more >
The event loop - JavaScript - MDN Web Docs - Mozilla
If there is no other message in the queue, and the stack is empty, the message is processed right after the delay. However,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found