3 ms·
The problem with this approach is merely adding the `async` keyword to a function would then significantly alter the way code is interpreted inside of the funct
by eridius 7y ago
The problem with this approach is merely adding the `async` keyword to a function would then significantly alter the way code is interpreted inside of the function. It seems like a non-starter to me to have adding the `async` keyword cause a function to stop compiling.
- Rusky 7y agoIn Kotlin this is not an issue, because you simply can't call an async function at all until you've added the async keyword (actually `suspend` in Kotlin). If you want to call an async function from a sync context, you just wrap it in an async block.
- eridius 7y agoWhat does an async block evaluate to? Does that wrap up the contents in Kotlin's equivalent of a Future? In any case, I'm a big fan of the idea that async/await is just syntax around something that can be done without the syntax (i.e. wrapping Futures that can otherwise be manipulated without the syntax).
- Rusky 7y agoYes, an async block (or `suspend` closure in Kotlin) just wraps up its contents in a future, applying the same state machine transform as would be applied to a top-level async function.