Hacker News new | ask | show | jobs
by kbsletten 2508 days ago
In my opinion, the main reason to have `async` is because it doesn't require knowledge of generators. I've worked with developers who thought that `async`/`await` was too much trouble to learn and unnecessarily complicated. Promises allow us to act like nothing changed and functions return values. The trick, to me, is how do you meet that need without sacrificing these more powerful operations.
1 comments

But it does require knowledge of generators. You're suspending a function during execution; that's what a generator is. We could've just named a global `async` that declares a coroutine FN on promises, and named `yield` as `await`, and the whole thing would look identical to now except for an extra paren and asterisk. You wouldn't need to understand their inner workings any more than you do with async/await now.
>But it does require knowledge of generators. You're suspending a function during execution; that's what a generator is.

That's like saying "Ordering from Amazon does require knowledge of driving a van. That's how the stuff comes to your home!".

No it's not. If the syntax is that similar, your metaphor makes no sense.