1

Referenced Answer: https://stackoverflow.com/a/4047607/347172


Basically, since the compiler is creating a state machine that uses recursion, is it possible that a class that has "too many" awaits will cause the compiler to generate code that will throw an exception?

Community
  • 1
  • 1
myermian
  • 31,823
  • 24
  • 123
  • 215
  • If you're asking if it's possible that the compiler generated state machine can run into a StackOverflowException, I would say it's possible because it's software but very very unlikely. Why are you asking? – Paulo Morgado May 26 '13 at 23:10
  • @PauloMorgado: To get a better understanding of how async/await works, and what it's limitations are. – myermian May 27 '13 at 03:25
  • OK. But I'm still wondering why this specific question. You're not if it's reentrant (which it isn't), you're asking if it's flawed. – Paulo Morgado May 27 '13 at 07:38

1 Answers1

5

Not in the way you're thinking. The compiler creates a state machine that will schedule itself, not call itself. The scheduling creates a "trampoline" which resets the stack.

Stephen Cleary
  • 437,863
  • 77
  • 675
  • 810