3 ms·
If `await` could be omitted, every async call would be blocking. Sometimes you don't want that It’s not a core detail though, you could have ‘nowait’ keyword f
by wruza 5y ago
If `await` could be omitted, every async call would be blocking. Sometimes you don't want that
It’s not a core detail though, you could have ‘nowait’ keyword for that, or a coroutine resume wrapper which returns a future/promise, or a coop-threading syntax like:
result = co.race [
expr1, expr2, expr3
]
The specific form is not important, and Promise is not incompatible with it, they could live together.
Promise/generator-based only cooperative multitasking is a trade-off between low-level layer complexity and userland syntax requirements. One can have first-class stackful coroutines, see e.g. Lua. The reason it’s not implemented in js is purely historical and socially-technical. It’s hard to convince browser makers to make all of their native interfaces coroutine-aware overnight.