Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can async-await be available in other .NET languages besides C#?

The async-await pattern is one of the more powerful additions to .NET 4.5 and C# 5.0

It is currently only available in C# and VB as far as I know.

Is this API a feature of the .NET CLR or of the C# compiler itself?

What I'm really asking is this - should we expect async/await in the other .NET languages such as:

  • C++ (via C++/CLI)
  • Python (via IronPython)
  • PHP (via Phalanger)
  • JavaScript (via IronJS)

Please note I'm not asking about asynchronous programming in general, but about the specifics of the async-await pattern (asynchronous code which is written synchronously).

like image 222
talkol Avatar asked Aug 28 '13 17:08

talkol


2 Answers

Is this API a feature of the .NET CLR or of the C# compiler itself?

This is a feature of the compiler. There were no CLR changes required to support async and await. Other languages would need to be extended to support it. There is nothing preventing a compiler from doing this, but it would have to be changed in the compiler and language itself.

C++ does support some asynchrony in Windows Store applications via task/then, though it's not as usable as the async/await keywords in C# and VB.

It is currently only available in C# and VB as far as I know

Note that F# also has async support (which predates the C# and VB.Net versions by quite a bit). It is different than the C# style async support, but similar (and inspired the C# and VB.Net teams).

like image 113
Reed Copsey Avatar answered Sep 18 '22 13:09

Reed Copsey


The C# and VB.Net compilers implement the await pattern by transforming the original method into a state machine. This is very similar to say how the F# async / work flow pattern works. This type of transformation is possible in any language that targets the CLR.

like image 43
JaredPar Avatar answered Sep 19 '22 13:09

JaredPar