3 ms·
OP, please Google "promise chaining", it will make your life so much better.
by snek 7y ago
OP, please Google "promise chaining", it will make your life so much better.
- sltkr 7y agoAt that point, why not go straight to async functions? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- agentultra 7y agoAt that point, why not go straight to monads? https://github.com/fluture-js/Fluture/tree/11.x https://github.com/fluture-js/Fluture/tree/11.x
- vimslayer 7y agoBecause one is a language feature and the other is yet another JS library made by some person.
- ofrzeta 7y agoI 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.
- doliveira 7y agoNot 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.