6 ms·
This looks very cool, thanks for sharing! I took a cursory look at the docs and it looks like async/await is pretty much directly analogous to how it works in
by mstade 5y ago
This looks very cool, thanks for sharing!
I took a cursory look at the docs and it looks like async/await is pretty much directly analogous to how it works in JS, with the difference that you don't need to mark functions as async in order to use the await keyword. Does this mean that if you use await in any function then any other function calling it will have to be refactored to add an await keyword, just like you have to refactor any call sites in JS if you make a function async?
I remember seeing someone here on HN showcasing a language where they did the opposite, making it so that await is implicit, so calling fetch or anything async doesn't require an additional keyword, and functions don't need to be refactored just to sprinkle async/await everywhere. I'll see if I can find that language again, but it seems to me there may be some idea sharing between the two that could perhaps yield some amazing features...
- minxomat 5y agoThat pretty much describes Lua.
- mstade 5y agoThanks for mentioning it, I don't know much about Lua. I found the language I was thinking of, it's called hyperscript. Here's an article about how async works in that language: https://hyperscript.org/posts/2021-04-06-aysnc-transparency-in-practice/ https://hyperscript.org/posts/2021-04-06-aysnc-transparency-...
- masklinn 5y agoSo… bog standard blocking interface, except it compiles to JS so it has to "surface" the async during the compilation process?
- derangedHorse 5y agoAsynchronous code can sometimes be difficult to write efficiently so having implicit awaits might help with avoiding accidentally made fire and forget calls. An interesting concept might be to explicitly call a function as asynchronous with a new keyword flipping the typical usage of ‘await’. I’d still advocate for the usage of ‘async’ in function signatures though as it helps when reasoning through an asynchronous code base.
- mstade 5y agoThis is exactly how I remember it working in the language I mention (which, by the way, is called hyperscript[1].) The semantics where flipped such that you'd explicitly mark calls or functions as async, rather than await, if you wanted them to run asynchronously. I run into subtle bugs all the time due to missing awaits, it's incredibly frustrating. [1]: https://hyperscript.org/posts/2021-04-06-aysnc-transparency-in-practice/ https://hyperscript.org/posts/2021-04-06-aysnc-transparency-...
- williamdclt 5y ago> I run into subtle bugs all the time due to missing awaits, it's incredibly frustrating. If you use TS, ESLint's `no-floating-promises` rule (or the equivalent in other linters) is _such_ a requirement
- masklinn 5y agoThat assumes all promise-generating code can be and is properly annotated, though.
- yunyu 5y agoTypescript will cover this!
- masklinn 5y agoTypescript lets you call into un-annotated libraries or annotate things as `any` or whatever.
- tekknik 5y agoYou can cover this with eslint: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unsafe-assignment.md https://github.com/typescript-eslint/typescript-eslint/blob/...
- recursivedoubts 5y agohttps://hyperscript.org https://hyperscript.org and its async transparency in particular: https://hyperscript.org/docs/#async https://hyperscript.org/docs/#async hyperscript isn't a general, full-stack programming language though, it's focused on pure front end stuff, sort of a modern jQuery replacement.