Skip to content

Instantly share code, notes, and snippets.

@kavitshah8
Last active August 29, 2015 14:26
Show Gist options
  • Save kavitshah8/e22dea9b95b0cbbc4261 to your computer and use it in GitHub Desktop.
Save kavitshah8/e22dea9b95b0cbbc4261 to your computer and use it in GitHub Desktop.
proimse-blog
var p = Promise.resolve().then(function() {
console.log('Promise resolve callback'); // Prints Promise resolve callback
}, function() {
console.log('Promise reject callback');
});
var p = Promise.reject().then(function () {
console.log('resolve1'); // This gets skipped due to rejection
})
.then(function () {
console.log('resolve2'); // This also gets skipped
}, function () {
console.error('reject2'); // Prints reject2
})
.catch(function () {
// This gets skipped because a previous error handler caught the failed promise
console.error('catch');
});
var p = Promise.reject().then(function () {
console.log('resolve1');
})
.then(function () {
console.log('resolve2');
})
.then(function () {
console.log('resolve3');
})
.catch(function () {
console.log('catch'); // Prints catch
});
var p = Promise.reject()
.then(function () {
console.log('resolve1');
}, function () {
console.log('reject1'); // Prints reject1
})
.then(function () {
console.log('resolve2'); // Prints resolve2
}, function () {
console.log('reject2');
})
.catch(function () {
console.log('catch');
});
var p = Promise.reject().then(function() {
console.log('Promise resolve callback');
}, function() {
console.log('Promise reject callback'); // Prints Promise reject callback
});
var p = Promise.resolve(1).then(function(value) {
console.log(value); // Prints 1
return 2;
})
.then(function(value) {
console.log(value); // Prints 2
});
var p = Promise.resolve().then(function(value) {
console.log(value); // Prints undefined
return 1;
})
.then(function(value) {
console.log(value); // Prints 1
});
var p = Promise.resolve().then(function(value) {
return 1;
})
.then(function(value) {
console.log('One', value); // Prints One, 1
})
.then(function(value) {
console.log('Two', value); // Prints Two, undefined
});
var p = Promise.resolve(1).then(function(value) {
console.log(value); // Prints 1
return Promise.resolve(2);
}).then(function(value) {
console.log(value); // Prints 2
});
var p = Promise.resolve(1).then(function(value) {
console.log(value); // Prints 1
}).then(function(value) {
// Prints undefined because nothing was returned in the previous promise
console.log(value);
});
var p = Promise.resolve(1)
.then(null)
.then(null)
.then(function(value) {
console.log(value); // Prints 1
})
.then(function(value) {
console.log(value); // Prints undefined
});
var p = Promise.reject().then(function() {
console.log('resolve1'); // This does not get invoked
}, function() {
console.error('reject1'); // Prints reject1
})
.catch(function() {
console.error('catch');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment