Proposal: Async Functions
Problem
Async Functions <a name="1"/>1 Async Functions This is a spec proposal for the addition of _Async Functions_ (also known as `async..await`) as a feature of TypeScript. <a name="2"/>2 Use Cases _Async Functions_ allow TypeScript developers to author functions that are expected to invoke an asynchronous operation and await its result without blocking normal execution of the program. This accomplished through the use of an ES6-compatible `Promise` implementation, and transposition of the function body into a compatible form to resume execution when the awaited asynchronous operation completes. This is based primarily on the Async Functions strawman proposal for ECMAScript, and C5.0 ยง 10.15 _Async Functions_. <a name="3"/>3 Introduction <a name="3.1"/>3.1 Syntax An _Async Function_ is a _JavaScript Function_, _Parameterized Arrow Function_, _Method_, or _Get Accessor_ that has been prefixed with the `async` modifier. This modifier informs the compiler that function body transposition is required, and that the keyword `await` should be treated as a unary expression instead of an identifier. An _Async Function_ must provide a return type annotation that points to a compatible `Promise` type. Return type inference can only be used if there is a globally defined, compatible `Promise` type. Example: [code block] <a name="3.2"/>3.2 Transformations To support this feature, the compiler needs to make certain transformations to the function body of an _Async Function_. The type of
Error Output
error = c[1]; s.label = g[1]; break; }
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: Proposal: Async Functions
This proposal looks great. Really looking forward to having this in TypeScript as asynchrony is so important, yet such a pain, in the JS world. I'm glad to see you're planning on supporting ES3/ES5 with async as well.
Trust Score
1 verification
- 1
This proposal looks great. Really looking forward to having this in TypeScript a
This proposal looks great. Really looking forward to having this in TypeScript as asynchrony is so important, yet such a pain, in the JS world. I'm glad to see you're planning on supporting ES3/ES5 with async as well.
Validation
Resolved in microsoft/TypeScript GitHub issue #1664. Community reactions: 0 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep