简体   繁体   中英

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

REST calls are basically stateless calls. 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.

where does the compiler or control stores information about the place from where it needs to process once the await call is completed.

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. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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