0

While I totally agree with the accepted answer on this SO post, I need to know if asynchronous recursion really creates a brand new call stack, why does it show the call stack building up in the browser in the following screenshot? To be fair, the call stack seems to stop growing after 32 recursions. Here's the sample code.

enter image description here

supertonsky
  • 2,563
  • 6
  • 38
  • 68
  • Does this answer your question? [Running an operation periodically when the length of operation is not known](https://stackoverflow.com/questions/62086948/running-an-operation-periodically-when-the-length-of-operation-is-not-known) – FZs Apr 15 '22 at 13:16
  • @FZs, thanks for that reference but that's actually similar to the SO post I've referenced in my post and does not really answer the question why it shows call stack building up in the browser. – supertonsky Apr 15 '22 at 13:19
  • Because the browser tries to be "smart" by putting it in context. Check [the comments after this one](https://stackoverflow.com/questions/62086948/running-an-operation-periodically-when-the-length-of-operation-is-not-known#comment109845073_62087241) on the post I linked. – FZs Apr 15 '22 at 13:29

2 Answers2

3

Showing async call stacks is a feature of chrome dev tools. You can switch it off with shift + ctrl + p and selecting do not capture async stack traces.

In the console output in your picture the bold text setTimeout(async) is where a new stack begins.

marzelin
  • 10,790
  • 2
  • 30
  • 49
2

Async does create new stacks.

Your browser's dev tools glue those async frames together for you as a debugging convenience.

You can turn it off in the dev tools' preferences; see eg. https://developer.chrome.com/blog/new-in-devtools-60/#async-stacks

AKX
  • 152,115
  • 15
  • 115
  • 172