Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the async/await transformation process specified?

In C#, the process for transforming LINQ query syntax into the actual code that gets executed is described in great detail in section 7.16 of the language specification, which makes it simple for a language developer to use it to implement similar query syntax on a new CLR language.

Is there any similarly detailed specification for the async/await syntax added in C# version 5? One of Eric Lippert's blog posts on the subject shows a before-and-after view of the transformation in a certain scenario, but that doesn't actually reveal the underlying rules in any useful level of detail. Does the specification for this exist somewhere?

EDIT: I can see that there's a section about await expressions and async functions in the C# language specification. It doesn't go into anywhere near the same level of detail as the LINQ section does, though. Essentially what I'm looking for is a process description that says "follow these steps to transform the code at the top of Eric's post into the state machine at the bottom of the post," such that a language designer could implement the feature in a different CLR language and end up having the same semantics.

like image 324
Mason Wheeler Avatar asked Dec 17 '14 23:12

Mason Wheeler


People also ask

How does async await work internally?

The async keyword turns a method into an async method, which allows you to use the await keyword in its body. When the await keyword is applied, it suspends the calling method and yields control back to its caller until the awaited task is complete. await can only be used inside an async method.

How does async await work in JS?

Inside an async function, you can use the await keyword before a call to a function that returns a promise. This makes the code wait at that point until the promise is settled, at which point the fulfilled value of the promise is treated as a return value, or the rejected value is thrown.

Is async await really asynchronous?

In computer programming, the async/await pattern is a syntactic feature of many programming languages that allows an asynchronous, non-blocking function to be structured in a way similar to an ordinary synchronous function.

What is the reason behind writing await inside async function only?

Await: Await function is used to wait for the promise. It could be used within the async block only. It makes the code wait until the promise returns a result. It only makes the async block wait.

How does await and async work in C #?

C# Await Async | How does Await and Async Work in C#? In C#, async and await keywords are used in asynchronous programming. Sometimes in our application, the UI gets blocked because of some process such as a long method running in our application.

What are async/await and promises?

Async/Await and Promises Explained The async / await operators make it easier to implement many async Promises. They also allow engineers to write clearer, more succinct, testable code. To understand this subject, you should have a solid understanding of how Promises work.

What is an asynchronous transformation?

In other words, you cannot pass each row along in the data flow as it is processed, but instead must output data asynchronously, or at a different time, than the input. For example, the following scenarios require an asynchronous transformation: The component has to acquire multiple buffers of data before it can perform its processing.

How do I recognize async and await members in the framework?

The .NET Framework 4.5 or higher contains many members that work with Async and Await. You can recognize these members by the "Async" suffix that's attached to the member name and a return type of Task or Task (Of TResult).


1 Answers

It seems to be a implementation detail as it tends to change. E.g. c#6 will introduce await in catch/finally clauses (the idea in general described here).

However, there are some deep-dive details about how awaiters are implemented in c#5. Look at links, especially this: Async Codegen (ppt).

Such that a language designer could implement the feature in a different CLR language and end up having the same semantics

I'd recommend to look at AsyncRewriter code.

like image 192
Sinix Avatar answered Sep 29 '22 16:09

Sinix