Chain Promises in Javascript
A chain promises to process data through a promise-laden gold field. A simple promise - let promiseToLog = new Promise(function(resolve, reject) { console.log("started"); setTimeout(function() { resolve("promise fulfilled.. after timeout"); }, 300); }); console.log("promise initialized"); promiseToLog.then(function(val) { console.log("resolver", val); }); As you have seen earlier the promise gets initialized and next statement (‘promise initialized’) gets executed without waiting to resolve promise. What if you want to execute something after the promise is resolved? This is where promise chaining comes in. You can chain the then statements to tie multiple executions to a single promise. ...