Javascript Promises in 10 Minutes
VloĆŸit
- Äas pĆidĂĄn 5. 09. 2024
- 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/dev...
Discord: / discord
Merch: cottonbureau.c...