February 2019
Beginner
694 pages
18h 4m
English
The final topic we will discuss on async await is how to process messages that are returned within our promises. Consider the following promise definition:
function asyncWithMessage() : Promise<string> {
return new Promise<string> (
( resolve: (message: string ) => void,
reject: (message: string) => void
) => {
function afterWait() {
resolve("resolve_message");
}
setTimeout(afterWait, 1000);
}
);
}
Here, we have defined a standard function returning a promise after a 1 second delay. The code to note here is the call to resolve within the afterWait function that is sending a message back to the callback. In this case, it is returning a string value of resolve_message, which matches our Promise<string> syntax. Again, we can ...
Read now
Unlock full access