Promises example
by Richard Hunter
JavaScript
function doThis() {
return Promise.reject();
}
function another() {
console.log('another');
return Promise.resolve();
}
function andAnother() {
console.log('and another');
return Promise.resolve();
}
function disaster() {
alert('Disaster!');
}
function success() {
console.log('success!')
return another()
.then(andAnother);
}
function failure() {
console.log('failure@$&*&*!!!');
return Promise.resolve();
}
doThis().then(success, failure).catch(disaster);