├── .gitignore ├── package.json ├── README.md ├── spec.emu └── index.html /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | package-lock.json 3 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "build": "npm run build-loose -- --strict", 5 | "build-loose": "ecmarkup --verbose spec.emu index.html" 6 | }, 7 | "devDependencies": { 8 | "ecmarkup": "^5.0.0" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ECMAScript proposal: `async do` expressions 2 | 3 | `async do` expressions allow you to introduce an asynchronous context within synchronous code without needing an immediately-invoked async function expression. 4 | 5 | This proposal builds off of the [`do` expressions proposal](https://github.com/tc39/proposal-do-expressions). 6 | 7 | This proposal has [preliminary spec text](https://tc39.github.io/proposal-async-do-expressions/). 8 | 9 | ## Motivation 10 | 11 | Currently the boundary between synchronous and asynchronous code requires defining and invoking an `async` function. In the case that you just want to perform a single operation, that's a lot of syntax for a relatively primitive operation: `(async () => {...})()`. This lets you write `async do {...}` instead. 12 | 13 | ## Examples 14 | 15 | ```js 16 | // at the top level of a script 17 | 18 | async do { 19 | await readFile('in.txt'); 20 | let query = await ask('???'); 21 | // etc 22 | } 23 | ``` 24 | 25 | ```js 26 | Promise.all([ 27 | async do { 28 | let result = await fetch('thing A'); 29 | await result.json(); 30 | }, 31 | async do { 32 | let result = await fetch('thing B'); 33 | await result.json(); 34 | }, 35 | ]).then(([a, b]) => console.log([a, b])); 36 | ``` 37 | -------------------------------------------------------------------------------- /spec.emu: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | title: Async do expressions 6 | stage: 0 7 | contributors: Kevin Gibbons 8 |9 | 10 |
`async do` expressions allow you to introduce an asynchronous context within synchronous code without needing an immediately-invoked async function expression.
13 |Unlike `do` expressions, `yield` can never be used within an `async do` expression.
TODO: pretty much the same list as for regular do expressions.
29 |The abstract operation AsyncDoStart takes arguments _promiseCapability_ (a PromiseCapability Record) and _block_ (a Parse Node for a |Block|). It performs the following steps when called:
42 |Unlike `do` expressions, `async do` expressions can be used in statement position.
async do expressions allow you to introduce an asynchronous context within synchronous code without needing an immediately-invoked async function expression.
Unlike do expressions, yield can never be used within an async do expression.
TODO: pretty much the same list as for regular do expressions.
2090 |The abstract operation AsyncDoStart takes arguments promiseCapability (a PromiseCapability
do doesn't await anything, step Unlike do expressions, async do expressions can be used in statement position.
© 2021 Kevin Gibbons
2126 | 2127 |All Software contained in this document ("Software") is protected by copyright and is being made available under the "BSD License", included below. This Software may be subject to third party rights (rights from parties other than Ecma International), including patent rights, and no licenses under such third party rights are granted under this license even if the third party concerned is a member of Ecma International. SEE THE ECMA CODE OF CONDUCT IN PATENT MATTERS AVAILABLE AT https://ecma-international.org/memento/codeofconduct.htm FOR INFORMATION REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT ECMA INTERNATIONAL STANDARDS.
2129 | 2130 |Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
2131 | 2132 |THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2139 | 2140 |