Promise.race 方法同样是将多个 Promise 实例,包装成一个新的 Promise 实例。当其中一个执行成功,就执行 then
<!doctype html>
<html>
<head>
</head>
<body>
<script>
const fetchRequest = (url) => {
return new Promise(async (resolve, reject) => {
let response = await fetch(url);
if (response.status === 200) {
let responseJson = await response.json();
resolve(responseJson);
} else {
reject(new Error('出错了'));
...