Echo JS 0.11.0

<~>
tracker1 3133 days ago. link 2 points
Is an async function just nicer syntactic sugar for a generator with a run(..) utility driving it?
    No.

That's not quite accurate... most implementations are using generator semantics under the covers afaik... as such a function can't be async and a generator... and I don't think that will ever be possible/practical.

That said, if you were writing your own custom scheduler, the generator syntax and being able to yield nothing would be useful... by the same token, you could create a defer method, to be used inside an async function `await defer();`, I also wrap setTimeout in a sleep function so that I can `await sleep(500)` or similar...

    const sleep = ms => new Promise(resolve=>setTimeout(resolve, ms));
    const defer = () => run(*() => { yield; });

Replies