简体   繁体   English

编译器如何知道在 await 调用后从哪里恢复控制

[英]How does the compiler know where to resume control after an await call

REST calls are basically stateless calls. REST 调用基本上是无状态调用。 Then when we make an await call to a third party api, where does the compiler or control stores information about the place from where it needs to process once the await call is completed.然后,当我们对第三方 api 进行 await 调用时,编译器或控件将有关在 await 调用完成后需要处理的位置的信息存储在何处。

where does the compiler or control stores information about the place from where it needs to process once the await call is completed.一旦 await 调用完成,编译器或控件在哪里存储有关它需要处理的位置的信息。

The async keyword does two things : it allows the use of the await keyword and it instructs the compiler to break up the async method into a state machine. async关键字有两件事:它允许使用await关键字,并指示编译器将async方法分解为状态机。 The gory details are here , but in summary:血腥的细节在这里,但总而言之:

The method is "split" at each use of await , with each "piece" of the method being a different part of the state machine.该方法在每次使用await “拆分”,方法的每个“部分”都是状态机的不同部分。 Then the current state of the state machine is saved (along with the values of local variables).然后保存状态机的当前状态(连同局部变量的值)。 When the awaited task completes, the continuation for that task executes the next step of the state machine.当等待的任务完成时,该任务的继续执行状态机的下一步。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM