Created
November 21, 2021 12:48
-
-
Save joynal/3c0caef30aa774ff082d435b7df8b7be to your computer and use it in GitHub Desktop.
This file contains 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
const job = (state) => new Promise((resolve, reject) => { | |
if (state) { | |
resolve('resolved'); | |
} else { | |
reject('rejected'); | |
} | |
}); | |
job(true) | |
.then((data) => { | |
console.log(data); | |
return job(true); | |
}) | |
.then((data) => { | |
if (data !== 'ok') { | |
throw 'release the kraken'; | |
} | |
return job(true); | |
}) | |
.then((data) => { | |
console.log(data); | |
}) | |
.catch((error) => { | |
console.error(error); | |
return job(false); | |
}) | |
.then((data) => { | |
console.log(data); | |
return job(true); | |
}) | |
.catch((error) => { | |
console.log(error); | |
return 'error caught'; | |
}) | |
.then((data) => { | |
console.log(data); | |
return new Error('all your base are belong to us'); | |
}) | |
.then((data) => { | |
console.log('success:', data.message); | |
}) | |
.catch((data) => { | |
console.log('error:', data.message); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment