4 ms·
> Synchronous or asynchronous is something up to the caller to the decide – not to the function itself. This doesn't work with Rusts implementation, because th
by Matthias247 7y ago
> Synchronous or asynchronous is something up to the caller to the decide – not to the function itself.
This doesn't work with Rusts implementation, because the functions have slightly different semantics and limitations.
E.g. an async function can't be recursive, since that would lead to a Future type of infinite size.
Async functions also don't necessarily run to completion like normal functions. They can instead also return at any .await point, which are implicit cancellation points. That means if someone just adds an async modifier to a function and some .await calls to methods inside it the result might not be correct anymore, since not all code in the function is guaranteed to be run anymore.
The cancellation mechanism was an explicit choice of the design - it would probably have been possible too to make async functions always run to completion and to thereby avoid the semantic difference.