DEV Community

Discussion on: Please don't nest promises

Collapse
 
smlka profile image
Andrey Smolko

Useful topic and nice post, great job!
Indeed promise nesting is widespread among novice developers.
In my opinion it happens coz Promise.then() still considered as a hook to attach callback on certain 'event' (as we did with callbacks) and the fact that Promise.then() RETURNS something is often missed.
Btw, just had a crazy idea. I think it might be better if a callback in Promise.then() must explicitly returns only promise (if you want to return value - Promise.resolve(100)) to avoid complexity with implicit wrapping.

Collapse
 
somedood profile image
Basti Ortiz

Well, it can help alleviate the confusion, but I recommend reading my recent article on best practices for ES6 promises. In it, I explained why it's best to refrain from wrapping values in promises as much as possible. I particularly discouraged the use of Promise.resolve, so I think that might be worth your read. 😉