December 2017
Beginner
372 pages
10h 32m
English
One of the real-world scenarios you will face is to call multiple async operations one after the other. Promises provide chaining which allows us to manage multiple calls. The then function will return a new promise which is different from the initial promise object and represents the completion of the previous promise operation and its callback.
The following is an example of how we can chain the promises:
let p:Promise<Board[]> = new Promise((resolve, reject) =>{ // do some async work if(success){ resolve(result); } else{ reject(errorMsg); }});let newPromise = p.then(boards=>doSomeMoreAsyncWork(boards));newPromise.then(result => console.log(result));
This code is an extension of our initial promise code where, after ...
Read now
Unlock full access