5 ms·
I understand the reasons why async/await is designed the way it is, but I still think it is backwards. Really if you wanted to truly make async programming appr
by mstade 9y ago
I understand the reasons why async/await is designed the way it is, but I still think it is backwards. Really if you wanted to truly make async programming approachable, you should make it transparent. What I mean by this is that instead of marking a function as async, and awaiting values, you'd mark lines as async, opting out of implicit awaits. I wrote up some thoughts on this here:
https://github.com/utilise/emitterify/issues/1#issuecomment-290943980 https://github.com/utilise/emitterify/issues/1#issuecomment-...
The way it is now, I defensively await things all over the place. What's worse, it propagates. If any of your function's dependencies are async, your function will also have to be async (or be ok with continuing operation after it's returned) and it turtles all the way down.
It is nicer than having to deal with promises directly though, there is that.
- maxxxxx 9y agoAgreed. Async is like a virus. Once you start somewhere pretty much everything else must be async too. In C# you can call async code from not async code and then call Task.Wait. Not sure if JS can do that. But it still beats promises or callback hell.....
- b34r 9y agoYou can't really transition between async and sync scopes, no.
- WorldMaker 9y agoA better term than virus is that async is a monad. Welcome to programming with monads. ;) JS async produces Promises like C# produces Task, so you can call an async function and use the result as a Promise.
- maxxxxx 9y agoCan you wait for a promise synchronously? I am pretty new to JS so please forgive if this is a stupid question.
- WorldMaker 9y agoIt's not something JS engines allow today. It's also not something that entirely makes sense from the perspective of a browser threading model or even the libuv-based NodeJS threading model.
- maxxxxx 9y agoI know. We have some wacky use cases where it would make sense. The real answer would probably be to say "Don't use Node for this" but that's a different discussion above my pay grade.
- WorldMaker 9y agoThe real answer is probably "those places you think need to synchronous don't need to be synchronous" and you need a refactor or a rearchitecture.
- maxxxxx 9y agoTrust me. We are not totally stupid. We need synchronous actions under some circumstances.
- pier25 9y ago> But it still beats promises or callback hell..... And then() hell ...