When comparing async functions to ES6 generator functions, it becomes clear:
function* x() {} // Generator function without 'yield'
Object.getPrototypeOf(x); // returns GeneratorFunction
Generator functions have their own unique characteristics compared to regular functions, but they don't necessarily require a yield
expression within their body. Initially, there was a reported bug in the ES6 proposal claiming that a generator function without yield
would be a syntax error, but this issue was promptly resolved:
One important use case is prototyping with a dummy generator or commenting out a yield for debugging purposes. This shouldn't result in making the program invalid.
The same principle applies to async functions: According to the draft, an async function can operate without any awaits
in its body while still functioning differently from a standard function.
Imagine if you were to comment out an await
; the interpreter shouldn't misconstrue your async function as a traditional function and potentially disrupt your entire codebase. It's best to avoid such pitfalls.