February 2019
Beginner
694 pages
18h 4m
English
Promises provide a simple syntax for handling these resolve and reject functions. Let's take a look at how we would use the promises defined in our previous code snippet, as follows:
function callDelayedPromise() {
console.log(`calling delayedPromise`);
delayedPromise().then(
() => { console.log(`delayedPromise.then()`) }
);
}
callDelayedPromise();
Here, we have defined a function named callDelayedPromise. This function logs a message to the console, and then calls our delayedPromise function. We are using fluent syntax to attach to the then function of the promise, and defining an anonymous function that will be called when the promise is resolved. The output of this code is as follows:
calling delayedPromise delayedPromise.then() ...
Read now
Unlock full access