Promise-then-catch
Promise function call with then and catch
JavaScript
function timeout(duration = 0) {
return new Promise((resolve, reject) => {
setTimeout(resolve, duration);
})
}
var p = timeout(1000).then(() => {
console.log('first then');
return timeout(2000);
}).then(() => {
console.log('2nd then');
throw new Error("hmm");
}).catch(err => {
console.log('got error from prev then of throw:'+err);
return Promise.all([timeout(100), timeout(200)]);
})