Created
August 7, 2018 07:56
-
-
Save YuCJ/647ecf0614ac4c653838abd32c443907 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
function getList() { | |
const list = [1, 2, 0, 3, 4] | |
return Promise.resolve(list) | |
} | |
function task() { | |
return new Promise((resolve, reject) => { | |
getList() | |
.then((list) => { | |
let hasFailure = false | |
console.log('1. log out list') | |
list.forEach(v => { | |
console.log(v) | |
if (v === 0) { | |
hasFailure = true | |
} | |
}) | |
if (hasFailure) { | |
reject(new Error('there is no zero')) | |
} | |
resolve('no zero') | |
}) | |
.then(() => { | |
console.log('2. other tasks') | |
}) | |
.catch(reject) | |
}) | |
} | |
task().then((r) => { console.log(r) }).catch(e => { console.log(e) }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment