Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> In that case JS is not colored either because an async function is simply a normal function that returns a Promise.

Exactly, IMHO at least, JS doesn't suffer from the coloring problem because you can call async functions from sync functions (because the JS Promise machinery allows to fall back to completion callbacks instead of using await). It's the 'virality' of await which causes the coloring problem, but in JS you can freely mix await and completion callbacks for async operations).



No, async and callbacks in JS are extremely viral. If a function returns a Promise or takes a callback, there is no possible way to execute it synchronously. Hence, coloring.

The reason this coloring isn't a problem for the JS ecosystem, is that it's a single-threaded language by design. So, async/callbacks are the only reasonable way to do anything external to the JS runtime (i.e. reading files, connecting to APIs, etc.)

(notwithstanding that node.js introduced some synchronous external operations in its stdlib - those are mostly unused in practice.)

To put it a different way - yes, JS has function coloring, but it's not a big deal because almost the entire JS ecosystem is colored red anyway.


await isn't viral per se, it's a purely local transformation. The virality is from CPS/callbacks and Promise.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: