DEV Community

Cover image for Struggling with Promises? You Are Not Alone!

Struggling with Promises? You Are Not Alone!

Somnath Singh on July 03, 2022

Do you like to cook? I’m not sure about you, but I enjoy cooking. I usually cook by myself, although I’m not opposed to having some help. Many tim...
Collapse
 
devash profile image
aayush

This is by far the best article I've read on explaining the concept of promises (I'm sure others will agree). 😊

Thank you so much for taking the time to write this. 🙏

Your hand-drawn illustrations and storytelling are fantastic.

You said you're not a master storyteller, Let me tell you:** You certainly are.**

You are exceptional. 🙌

Anyone can make people believe they are intelligent by rambling on about complicated concepts, but the true genius is the one who can explain these concepts to a child. In this article, you have done just that.

I hope to see you among dev.to top writers.

Collapse
 
sainig profile image
Gaurav Saini

I’m sorry I didn’t read the full post yet, but just from the first few paragraphs and especially the food ingredient analogy is just too good. I had to stop and write this comment.
I “promise” I’ll read the full post. nervous laughter intensifies 😬

Collapse
 
harithzainudin profile image
Muhammad Harith Zainudin

so, have you resolved your promise? haha

Collapse
 
sainig profile image
Gaurav Saini

Haha! yes, I sure did 🙂

Collapse
 
peerreynders profile image
peerreynders

Just to add:

When a promise is no longer pending it is considered settled.

Promise.allSettled() - JavaScript | MDN

The Promise.allSettled() method returns a promise that resolves after all of the given promises have either fulfilled or rejected, with an array of objects that each describes the outcome of each promise.

favicon developer.mozilla.org

console.log('Vacuuming');
const promise = Promise.resolve().then(() => console.log('Picking up Milk'));
console.log('Washing the Dishes');
promise.then(() => console.log('Take a break'));
console.log('Done inside');
/* 
  Output:
  "Vacuuming"
  "Washing the Dishes"
  "Done inside"
  "Picking up Milk"
  "Take a break"
*/
Enter fullscreen mode Exit fullscreen mode

It's sometimes useful to remember that just because a promise value has settled doesn't mean that it will immediately get processed if something synchronous is currently being processed. One can then onto an already settled promise but the processing will still occur asynchronously.

Also recursively settling promises is the fastest way to starve the event loop.

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️
promise.then(onFulfilled)
promise.catch(onFailure)
// We can write it like this also

promise.then(onFulfilled).catch(onFailure)
Enter fullscreen mode Exit fullscreen mode

It should be pointed out that this isn't actually the same, and may behave differently in certain cases.

Collapse
 
grantdotdev profile image
Grant Riordan

Great article ! A well rounded way of describing promises. Question - what did you use / how did you create your illustrations / storyboard. Im looking for something myself for my articles (I'm very poor at drawing).

Collapse
 
harithzainudin profile image
Muhammad Harith Zainudin

Good explanation! Thank you!

One things tho, which website/apps you use to make the hand drawn illustrations with the code like this one

im curious tho

Collapse
 
suchintan profile image
SUCHINTAN DAS

Thanks Somnath, it's a good explanation of promises and the story illustration is really amazing.

Just a small suggestion. Please try to use little bit space between the main headings. It sometimes looks like the whole thing is too much stuff into a small space which can be irritating for a reader who is going through the whole blog.

Hope this helps ✌ !

Collapse
 
ajshivali profile image
Shivali Pandey

Nice work!! very good.

Collapse
 
robole profile image
Rob OLeary

Good job!

Collapse
 
abdulrahman_ali profile image
Abdulrahman Ali

That was a great read. Really simple and informative. Thanks Somnath.

Collapse
 
conorluddy profile image
Conor

Love the cartoons :D

Collapse
 
nicklane profile image
Nicholas Lane

Thanks, I think I really needed this kind of article to get my head around promises!
Great read.

Collapse
 
leeuw profile image
leeuw

thanks bro. it was really helpful.

Collapse
 
devash profile image
aayush • Edited

The title should be: Promises Made Easy. 🎉