Created
April 13, 2020 03:28
-
-
Save wujunchuan/51f28cb6e7893547d720d0e40076d5b9 to your computer and use it in GitHub Desktop.
Document // source https://jsbin.com/neluxit
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Document</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
console.clear(); | |
Promise.all([Promise.resolve({ | |
code: 200, | |
list: [] | |
}), Promise.reject({ | |
code: 500, | |
msg: 'Sever error' | |
})]).then(res => { | |
console.log(res) | |
}).catch(e => { | |
console.log(e) | |
}) | |
Promise.allSettled([Promise.reject({ | |
code: 500, | |
msg: 'Server error' | |
}), Promise.resolve({ | |
code: 200, | |
list: [] | |
})]).then(res => { | |
console.log(res[0]); | |
}).catch(e => { | |
console.log(e) | |
}) | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">console.clear(); | |
Promise.all([Promise.resolve({ | |
code: 200, | |
list: [] | |
}), Promise.reject({ | |
code: 500, | |
msg: 'Sever error' | |
})]).then(res => { | |
console.log(res) | |
}).catch(e => { | |
console.log(e) | |
}) | |
Promise.allSettled([Promise.reject({ | |
code: 500, | |
msg: 'Server error' | |
}), Promise.resolve({ | |
code: 200, | |
list: [] | |
})]).then(res => { | |
console.log(res[0]); | |
}).catch(e => { | |
console.log(e) | |
})</script></body> | |
</html> |
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
console.clear(); | |
Promise.all([Promise.resolve({ | |
code: 200, | |
list: [] | |
}), Promise.reject({ | |
code: 500, | |
msg: 'Sever error' | |
})]).then(res => { | |
console.log(res) | |
}).catch(e => { | |
console.log(e) | |
}) | |
Promise.allSettled([Promise.reject({ | |
code: 500, | |
msg: 'Server error' | |
}), Promise.resolve({ | |
code: 200, | |
list: [] | |
})]).then(res => { | |
console.log(res[0]); | |
}).catch(e => { | |
console.log(e) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The new allSettled behaves differently. It resolves whenever all of the promises finished working, that is, became either fulfilled or rejected. It resolves to an array that contains both the status of the promise and what it resolved to (or an error).