I can’t see what’s the utility of the Promise, could someone please provide a practical example?
there are lessons on Freecodecamp on this.
The first sentence is:
You make the promise to your parents, that you will learn coding.
Then their lives go on and they do their stuff.
After some time you come back to them and either go like “Yes, I did it!” (fulfill the promise) or “No, I didn’t.” (reject the promise).
They didn’t stop their lives and waited for you (sync),
you made a promise and worked in the background (async).
A real-world analogy i use often is the case of a restaurant. When the kitchen gets your order slip, that is a Promise. At some future time, it will resolve (and the wait staff will bring your food) or reject (and you’ll be informed that they’re our of tofu).
One of the most common uses for Promises has been retrieving remote data. Rather than leave your script hanging till the data arrives, with Promises we can do other things whilewe wait.
The internet has lots of documentation about promises.
Is there a particular problem you are trying to solve with promises and you are not able to find solution for?
Thank you for the analogy, it’s so helpful.