Javascript Promises in 10 Minutes
Вставка
- Опубліковано 11 лют 2019
- What's a Promise?
A Promise is an object that acts as a placeholder for some value or operation that is soon to complete or return. Promises are similar to callbacks in that they are both used to control the execution order of a program. If you have 2 asynchronous (not occuring in any particular order) events A and B, and you need to ENSURE that Event B begins ONLY AFTER Event A completes, you can wrap Event A with a Promise object. This promise executes Event A and then gives you the option to either 'resolve' or 'reject' the Promise.
The Promise should be resolved if Event A was executed successfully with no errors. When a Promise is resolved, a special success callback function is triggered. This callback can execute Event B. A Promise should be rejected if Event A failed to complete successfully or produced an error. When a Promise is rejected, a special failure callback is triggered that can be used to carry out error handling tasks.
🌎 Find Me Here:
Twitter: / realdevsage
Ebooks: payhip.com/devsage
Discord: / discord
Merch: cottonbureau.com/people/devsage
💙 Twitter: twitter.com/realDevSage
📙 Ebooks: payhip.com/devsage
💥 Discord: discord.gg/BP8wPv6raA
I love your tutorials, you are truly a life savior!
Glad you like them!
Thanks!!! The best explanation, even better that on MDN web docs!!! How long you bin doing programming? Do you have blog?
I appreciate that. I've been coding for around 7 years now. I do have a blog but I don't really post on it a lot.
Now to explain async and await! Which is the better alternative to promises with ES6.
Great!
Thanks!