December 2017
Beginner
372 pages
10h 32m
English
The signature of the promise takes a function which will do some asynchronous work. This function itself takes two parameters, resolve and reject. These parameters allow the function to inform a promise if the operation was a success or a failure. If the operation was successful, we call the resolve function, which informs the promise of the success, and we can pass the return value from our async operation to the resolve function. The following is the code snippet of a promise:
let p:Promise<Board[]> = new Promise((resolve, reject) =>{ // do some asyn work if(success){ resolve(result); } else{ reject(errorMsg); }});
Here we are creating a new Promise object and passing an arrow function to it. This arrow function takes two parameters ...
Read now
Unlock full access