So this would be possible:
async function f1() {
f2();
}
function f2() {
await fetch('something');
...
}
Instead of having to async each and every function and await each and every function call: async function f1() {
await f2();
}
async function f2() {
await fetch('something');
...
}
Which is what TFA complains about and what indeed is a pain in the ass.One could imagine a language where an await from sync code was syntactic sugar for such a function call, but generally the async/await syntax serves as a way to deliberately segregate your sync and async code. So that would defeat the purpose. At that point it might make more sense to design the language like Go and make everything async. (Preemptive runtimes like Java's virtual threads are another option.)
There was a good blog post I want to link here where the author argued that async/await is making explicit the fundamental property of some functions being expensive, as a counterpoint to TFA, but I haven't been able to find it again. But they made the case that expensive operations are fundamentally viral, and async/await was only making this explicit and wasn't unjustified overhead as some argue.
[1] https://docs.python.org/3/library/asyncio-task.html#asyncio....
function f1() {
x = await fetch('something');
...
}
Into this: function f1() {
fetch('something').then(x => {
...
});
}Also think how this should be translated: function f1() { x = await fetch('something'); return x + 1; }