Hacker News new | ask | show | jobs
by snek 2493 days ago
OP, please Google "promise chaining", it will make your life so much better.
1 comments

At that point, why not go straight to async functions?

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

At that point, why not go straight to monads?

https://github.com/fluture-js/Fluture/tree/11.x

Because one is a language feature and the other is yet another JS library made by some person.
I don't really get why people need to use async methods (regardless if they are promises or something else) when in fact they are implementing a blocking workflow where one method call needs the results of a preceding method call. It would be much easier to just use synchronized/blocking functions because then you get the desired behaviour for free and need not jump through hoops like promises chaining.

I get that there are APIs that are only available in an async fashion these days and I was forced to bolt on an blocking workflow on an async API myself and didn't particularly enjoy it.

Not sure I understand your complaint. Don't promises ultimately wait upon external events, like a connection receiving data or a timeout being triggered? Given that Javascript is single threaded it is the only way of not blocking the event loop.