DEV Community

the furious dev
the furious dev

Posted on

Promise Explained like I'm 5.

This is based on my understanding of Promise, feel free to correct me if you think there's something wrong with my explanation :P

Now imagine yourself running an errand for your mom while she's out working. She told you two things:

  1. Clean the house
  2. Buy pizza for dinner

Your typical approach would be cleaning the house for whole day, afterwards go out of the house to buy some pizza. This process would take much time as you have to walk out of the house, wait in line just to get yourself some of that tasty pizza.

A better way we could have done it is, call a pizza guy, and tell him to have the pizza delivered at certain time, and clean the house afterwards.

What does it have to do with promise? You have executed the pizza task without have to wait for it, then you go clean the house, after some time, the pizza may have arrived at same time you have finished cleaning the house.

TL;DR: Promise is (as far as I understand it) executing whatever process you have but without having to wait for an actually result.

Top comments (5)

Collapse
 
jcuffe profile image
Jared Cuffe

You're on the right track - to expand on your metaphor, we're going to add another concept: paying for the pizza!

In your first example, when you go to order the pizza, you have to stand there and wait for the pizza to be made so that you can pay for it and leave.

When you call the pizza for delivery, though, you can go off and do other things while the pizza is being made, and when the pizza arrives at your door, you are able to pay for it then!

So, in both cases, you are waiting for your pizza to be made, so that you can pay for it. With promises, you can do other things, like clean your house, while the pizza is being made, and you are still able to pay for it just as quickly as you would have if you had sat in the shop watching it cook!

Collapse
 
wstocker profile image
Wendy Stocker

Check out this post: dev.to/jessitron/promises-in-javas...

Has a great explanation with yard and legos.

Collapse
 
pranay_rauthu profile image
pranay rauthu

Check this amazing talk by jake youtube.com/watch?v=cCOL7MC4Pl0

Collapse
 
ronaldoperes profile image
Ronaldo Peres

Nice,

Is this like the Task.Run() from C#?

Collapse
 
ekimkael profile image
Ekim Kael • Edited

So if understand it's like:

  • Resolve this problem but you don't have to give me a response right now.When you think you've finish, come and show me

am I right?