In the next video, you'll look at an example in action to see the impact of resolve() callback on the internal properties of a promise object.
In the last video, you looked at example code and saw how invoking the resolve() callback inside the producer code changes the Status property to ‘resolved’ and the Value property to whatever is passed as an argument while resolving the promise.
Following is the example code which you looked at in the video:
Code Snippet:
// resolving a promise promiseObj = new Promise((resolve, reject) => { console.log("Getting name from DB..."); setTimeout(() => { resolve("Srishti"); }, 3000); }); console.log(promiseObj);
Output:
Getting name from DB... Promise {<resolved>} __proto__: Promise [[PromiseStatus]]: "resolved" [[PromiseValue]]: "Srishti"
Now is the turn to look at the reject() callback in action and witness its impact on the internal properties of the promise object. You’ll look at that in the next video.
In the last video, you looked at example code and saw how invoking the reject() callback inside the producer code changes the Status property to ‘rejected’ and the Value property to whatever is passed as an argument while rejecting the promise.
Following is the example code which you looked at in the video:
Code Snippet:
// rejecting a promise let promiseObj = new Promise((resolve, reject) => { console.log("Getting name from DB..."); setTimeout(() => { reject(new Error("Could not get the name from DB!")); }, 3000); }); console.log(promiseObj);
Output:
Getting name from DB... Promise {<rejected>: Error: Could not get the name from DB! at setTimeout} __proto__: Promise [[PromiseStatus]]: "rejected" [[PromiseValue]]: Error: Could not get the name from DB! at setTimeout Uncaught (in promise) Error: Could not get the name from DB! at setTimeout
Till now, you have learned that when you invoke the resolve() callback method in the producer code, the promise is 'resolved'. On the other hand, when you invoke the reject() callback method in the producer code, the promise is 'rejected'. But what would happen if you do both? Wondering what? You’ll look at that in the next video with Srishti.
Alright, that was a lot to consume about promises. You’ll hear from Srishti the summary of what you learned till now about the promises.