Await expressions
The await operator is used to suspend evaluation of the enclosing async function until the asynchronous operation represented by the operand has completed. await-expression: An await-expression is only allowed in the body of an async function (§10.14). Within the nearest enclosing async function, an await-expression may not occur in these places: · Inside a nested (non-async) anonymous function · In a catch or finally block of a try-statement · Inside the block of a lock-statement · In an unsafe context Note that an await-expression cannot occur in most places within a query-expression, because those are syntactically transformed to use non-async lambda expressions. Inside of an async function, await cannot be used as an identifier. There is therefore no syntactic ambiguity between await-expressions and various expressions involving identifiers. Outside of async functions, await acts as a normal identifier. The operand of an await-expression is called the task. It represents an asynchronous operation that may or may not be complete at the time the await-expression is evaluated. The purpose of the await operator is to suspend execution of the enclosing async function until the awaited task is complete, and then obtain its outcome.
|