Created
January 6, 2016 16:49
-
-
Save pfeilbr/9365eea196ab4ad5a3df to your computer and use it in GitHub Desktop.
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
// Promise series example | |
function task(name) { | |
return new Promise(function(resolve, reject) { | |
setTimeout(function() { | |
console.log(name, new Date()); | |
if (name === 'fail') { | |
reject(name); | |
} else { | |
resolve(name); | |
} | |
}, 2000); | |
}); | |
} | |
task('t1') | |
.then(function(resp) { | |
return task('t2'); | |
}) | |
.then(function(resp) { | |
return task('fail'); // force fail | |
}) | |
.then(function(resp) { | |
return task('t3'); | |
}) | |
.then(function(resp) { | |
console.log(resp, 'done'); | |
}) | |
.catch(function(err) { | |
console.error(err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment