David Herman (2014-01-27T19:09:32.000Z)
domenic at domenicdenicola.com (2014-01-30T15:50:46.375Z)
I'd like to suggest another sense in which you may have gone down a bad path: you're assuming that await is paired with function*, but it could instead be (like C#) paired with its own async-function syntactic form. Let's say for the sake of argument that async is just a keyword that takes a function form: ```js async function sizeOfZombocom() { let all = await download("http://zombo.com"); return all.length; } ``` Imagine we were designing this with a macro system like sweet.js. The temptation is for `async` to unhygienically bind `await` to a macro within its body, but Racket has developed a cleaner mechanism for thinking about paired forms like this, which they call "syntax parameters" (kind of a confusingly generic sounding name) [1] [2]. The basic idea is that you bind both `async` and `await` at the same time, so `await` is always bound, even outside of an async function, but the two collaborate so that `async` informs `await` of its syntactic context. So it would look something like this: Example 1: ```js import { async, await } from "async"; await 1; // syntax error: await used outside of async function ``` Example 2: ```js import { async, await } from "async"; function* sizeOfZombocom() { let all = await download("http://zombo.com"); // syntax error: await used outside of async function return all.length; } ``` Example 3: ```js import { async, await } from "async"; async function sizeOfZombocom() { let all = await download("http://zombo.com"); // great success return all.length; } ``` This makes your abstraction airtight: `await` is a concept that belongs to `async` functions, not generator functions; generator functions are merely the internal implementation technique. Currently, sweet.js doesn't have syntax parameters, but it'd be a good experiment to add them them and try implementing async/await as I've sketched here. [1]: http://www.greghendershott.com/fear-of-macros/Syntax_parameters.html [2]: http://docs.racket-lang.org/reference/stxparam.html