Last active
August 29, 2015 14:26
-
-
Save kavitshah8/e22dea9b95b0cbbc4261 to your computer and use it in GitHub Desktop.
proimse-blog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var p = Promise.resolve().then(function() { | |
console.log('Promise resolve callback'); // Prints Promise resolve callback | |
}, function() { | |
console.log('Promise reject callback'); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var p = Promise.reject().then(function() { | |
console.log('Promise resolve callback'); | |
}, function() { | |
console.log('Promise reject callback'); // Prints Promise reject callback | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var p = Promise.resolve(1).then(function(value) { | |
console.log(value); // Prints 1 | |
return 2; | |
}) | |
.then(function(value) { | |
console.log(value); // Prints 2 | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var p = Promise.resolve().then(function(value) { | |
console.log(value); // Prints undefined | |
return 1; | |
}) | |
.then(function(value) { | |
console.log(value); // Prints 1 | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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