{"id":32396,"date":"2024-11-25T14:18:39","date_gmt":"2024-11-25T06:18:39","guid":{"rendered":"https:\/\/fwq.ai\/blog\/32396\/"},"modified":"2024-11-25T14:18:39","modified_gmt":"2024-11-25T06:18:39","slug":"javascript%e4%b8%ad%e4%bd%bf%e7%94%a8promise-all%e5%92%8cpromise-allsettled%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/32396\/","title":{"rendered":"JavaScript\u4e2d\u4f7f\u7528Promise.all()\u548cPromise.allSettled()\u65b9\u6cd5"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/887\/227\/169340072149964.jpg\" class=\"aligncenter\" title=\"JavaScript\u4e2d\u4f7f\u7528Promise.all()\u548cPromise.allSettled()\u65b9\u6cd5\u63d2\u56fe\" alt=\"JavaScript\u4e2d\u4f7f\u7528Promise.all()\u548cPromise.allSettled()\u65b9\u6cd5\u63d2\u56fe\" \/><\/p>\n<p>\u672c\u6559\u7a0b\u5c06\u6559\u60a8\u5982\u4f55\u5728 JavaScript \u4e2d\u4f7f\u7528 Promise \u7b49\u5f85\u3002<\/p>\n<p>\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u5c06\u6559\u60a8\u6709\u5173 Promise.all() \u548c Promise.allSettled() \u65b9\u6cd5\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u5b83\u4eec\u6765\u5904\u7406\u591a\u4e2a Promise\u3002<\/p>\n<h2>\u4f7f\u7528 Promise.all() \u65b9\u6cd5<\/h2>\n<p>Promise \u5bf9\u8c61\u5177\u6709\u4e09\u4e2a\u6709\u7528\u7684\u65b9\u6cd5\uff0c\u540d\u4e3a then()\u3001catch() \u548c finally()\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u5b83\u4eec\u5728 Promise \u5b8c\u6210\u65f6\u6267\u884c\u56de\u8c03\u65b9\u6cd5\u3002 p&gt; <\/p>\n<p>Promise.all() \u65b9\u6cd5\u662f\u4e00\u4e2a\u9759\u6001\u65b9\u6cd5\uff0c\u8fd9\u610f\u5473\u7740\u5b83\u5c5e\u4e8e\u6574\u4e2a\u7c7b\uff0c\u800c\u4e0d\u662f\u7ed1\u5b9a\u5230\u8be5\u7c7b\u7684\u4efb\u4f55\u7279\u5b9a\u5b9e\u4f8b\u3002\u5b83\u63a5\u53d7\u53ef\u8fed\u4ee3\u7684 Promise \u4f5c\u4e3a\u8f93\u5165\u5e76\u8fd4\u56de\u5355\u4e2a Promise \u5bf9\u8c61\u3002<\/p>\n<p>\u6b63\u5982\u6211\u4e4b\u524d\u63d0\u5230\u7684\uff0cPromise.all() \u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684 Promise\u3002\u5982\u679c\u4f20\u9012\u7ed9\u8be5\u65b9\u6cd5\u7684\u6240\u6709\u627f\u8bfa\u90fd\u5df2\u6210\u529f\u89e3\u6790\uff0c\u5219\u6b64\u65b0\u627f\u8bfa\u5c06\u89e3\u6790\u4e3a\u5df2\u786e\u5b9a\u627f\u8bfa\u503c\u7684\u6570\u7ec4\u3002\u4e00\u65e6\u901a\u8fc7\u7684\u627f\u8bfa\u4e4b\u4e00\u88ab\u62d2\u7edd\uff0c\u8fd9\u4e2a\u65b0\u7684\u627f\u8bfa\u4e5f\u5c06\u88ab\u62d2\u7edd\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<h3>\u6240\u6709 Promise \u5747\u6210\u529f\u89e3\u51b3<\/h3>\n<p>\u4ee5\u4e0b\u662f Promise.all() \u65b9\u6cd5\u7684\u793a\u4f8b\uff0c\u5176\u4e2d\u6240\u6709 Promise \u5747\u5df2\u6210\u529f\u89e3\u6790\uff1a<\/p>\n<pre>const promise_a = new Promise((resolve) =&amp;gt; {\n  setTimeout(() =&amp;gt; {\n    resolve('Loaded Textures');\n  }, 3000);\n});\n\nconst promise_b = new Promise((resolve) =&amp;gt; {\n    setTimeout(() =&amp;gt; {\n      resolve('Loaded Music');\n    }, 2000);\n});\n\nconst promise_c = new Promise((resolve) =&amp;gt; {\n    setTimeout(() =&amp;gt; {\n      resolve('Loaded Dialogues');\n    }, 4000);\n});\n\n\nconst promises = [\n  promise_a, promise_b, promise_c\n];\n\nconsole.log('Hello, Promises!');\n\nPromise.all(promises).then((values) =&amp;gt; {\n  console.log(values);\n  console.log('Start the Game!');\n});\n\n\/* Output\n\n19:32:06 Hello, Promises!\n19:32:10 Array(3) [ \"Loaded Textures\", \"Loaded Music\", \"Loaded Dialogues\" ]\n19:32:10 Start the Game!\n\n*\/\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6211\u4eec\u5728\u8c03\u7528 Promise.all() \u65b9\u6cd5\u4e4b\u524d\u7684\u8bed\u53e5\u8bb0\u5f55\u4e8e 19:32:06\u3002\u6b64\u5916\uff0c\u6211\u4eec\u7684\u7b2c\u4e09\u4e2a Promise \u540d\u4e3a promise_c \u9700\u8981\u6700\u957f\u7684\u65f6\u95f4\u624d\u80fd\u89e3\u51b3\uff0c\u5e76\u5728 4 \u79d2\u540e\u89e3\u51b3\u3002\u8fd9\u610f\u5473\u7740\u8c03\u7528 all() \u65b9\u6cd5\u8fd4\u56de\u7684 Promise \u4e5f\u5e94\u8be5\u9700\u8981 4 \u79d2\u624d\u80fd\u89e3\u6790\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5c06\u56de\u8c03\u51fd\u6570\u4f20\u9012\u7ed9 then() \u65b9\u6cd5\u6765\u9a8c\u8bc1\u662f\u5426\u9700\u8981 4 \u79d2\u624d\u80fd\u89e3\u6790\u3002<\/p>\n<p>\u8fd9\u91cc\u9700\u8981\u6ce8\u610f\u7684\u53e6\u4e00\u4ef6\u91cd\u8981\u4e8b\u60c5\u662f\uff0c\u8fd4\u56de\u7684\u5df2\u5b8c\u6210\u503c\u6570\u7ec4\u5305\u542b\u8fd9\u4e9b\u503c\u7684\u987a\u5e8f\u4e0e\u6211\u4eec\u5c06 Promise \u4f20\u9012\u7ed9 Promise.all() \u65b9\u6cd5\u7684\u987a\u5e8f\u76f8\u540c\u3002\u540d\u4e3a promise_b \u7684 Promise \u89e3\u6790\u901f\u5ea6\u6700\u5feb\uff0c\u53ea\u9700 2 \u79d2\u3002\u4f46\u662f\uff0c\u5176\u89e3\u6790\u503c\u4ecd\u7136\u4f4d\u4e8e\u8fd4\u56de\u6570\u7ec4\u4e2d\u7684\u7b2c\u4e8c\u4e2a\u4f4d\u7f6e\u3002\u8fd9\u4e0e\u6211\u4eec\u5c06 Promise \u4f20\u9012\u7ed9 Promise.all() \u65b9\u6cd5\u7684\u4f4d\u7f6e\u76f8\u5339\u914d\u3002<\/p>\n<p>\u8fd9\u79cd\u79e9\u5e8f\u7684\u7ef4\u62a4\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u975e\u5e38\u6709\u5e2e\u52a9\u3002\u4f8b\u5982\uff0c\u5047\u8bbe\u60a8\u6b63\u5728\u4f7f\u7528\u5341\u4e2a\u4e0d\u540c\u7684 Promise \u83b7\u53d6\u6709\u5173\u5341\u4e2a\u4e0d\u540c\u57ce\u5e02\u7684\u5929\u6c14\u4fe1\u606f\u3002\u6240\u6709\u8fd9\u4e9b\u95ee\u9898\u4e0d\u4f1a\u540c\u65f6\u5f97\u5230\u89e3\u51b3\uff0c\u800c\u4e14\u4e0d\u53ef\u80fd\u4e8b\u5148\u77e5\u9053\u5b83\u4eec\u7684\u89e3\u51b3\u987a\u5e8f\u3002\u4f46\u662f\uff0c\u5982\u679c\u60a8\u77e5\u9053\u6570\u636e\u6309\u7167\u4f20\u9012 Promise \u7684\u987a\u5e8f\u8fd4\u56de\uff0c\u60a8\u5c06\u80fd\u591f\u6b63\u786e\u5206\u914d\u5b83\u4ee5\u4f9b\u4ee5\u540e\u64cd\u4f5c\u3002<\/p>\n<h3>\u4e00\u4e2a\u627f\u8bfa\u88ab\u62d2\u7edd<\/h3>\n<p>\u4ee5\u4e0b\u662f\u5176\u4e2d\u4e00\u4e2a\u627f\u8bfa\u88ab\u62d2\u7edd\u7684\u793a\u4f8b\uff1a<\/p>\n<pre>const promise_a = new Promise((resolve) =&amp;gt; {\n  setTimeout(() =&amp;gt; {\n    resolve('Loaded Textures');\n  }, 3000);\n});\n\nconst promise_b = new Promise((resolve, reject) =&amp;gt; {\n    setTimeout(() =&amp;gt; {\n      reject(new Error('Could Not Load Music'));\n    }, 2000);\n});\n\nconst promise_c = new Promise((resolve) =&amp;gt; {\n    setTimeout(() =&amp;gt; {\n      resolve('Loaded Dialogues');\n    }, 4000);\n});\n\n\nconst promises = [\n  promise_a, promise_b, promise_c\n];\n\nconsole.log('Hello, Promises!');\n\nPromise.all(promises).catch((error) =&amp;gt; {\n  console.error(error.message);\n  console.log('Stop the Game!');\n});\n\n\/* Output\n\n20:03:43 Hello, Promises!\n20:03:45 Could Not Load Music\n20:03:45 Stop the Game!\n\n*\/\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u540c\u6837\uff0c\u6211\u4eec\u5728\u8c03\u7528 all() \u65b9\u6cd5\u4e4b\u524d\u7684\u8bed\u53e5\u8bb0\u5f55\u4e8e 20:03:43\u3002\u7136\u800c\uff0c\u6211\u4eec\u7684\u7b2c\u4e8c\u4e2a\u627f\u8bfa promise_b \u8fd9\u6b21\u4ee5\u62d2\u7edd\u544a\u7ec8\u3002\u6211\u4eec\u53ef\u4ee5\u770b\u5230 promise_b \u5728 2 \u79d2\u540e\u88ab\u62d2\u7edd\u3002\u8fd9\u610f\u5473\u7740 all() \u65b9\u6cd5\u8fd4\u56de\u7684 Promise \u4e5f\u5e94\u8be5\u5728 2 \u79d2\u540e\u62d2\u7edd\uff0c\u5e76\u51fa\u73b0\u4e0e\u6211\u4eec\u7684 promise_b \u76f8\u540c\u7684\u9519\u8bef\u3002\u4ece\u8f93\u51fa\u4e2d\u53ef\u4ee5\u660e\u663e\u770b\u51fa\uff0c\u8fd9\u6b63\u662f\u53d1\u751f\u7684\u60c5\u51b5\u3002<\/p>\n<h3>\u4e0e await \u5173\u952e\u5b57\u4e00\u8d77\u4f7f\u7528<\/h3>\n<p>\u60a8\u53ef\u80fd\u5df2\u7ecf\u77e5\u9053 await \u5173\u952e\u5b57\u7528\u4e8e\u7b49\u5f85\u627f\u8bfa\u89e3\u51b3\uff0c\u7136\u540e\u518d\u7ee7\u7eed\u4e0b\u4e00\u6b65\u3002\u6211\u4eec\u8fd8\u77e5\u9053 all() \u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a\u627f\u8bfa\u3002\u8fd9\u610f\u5473\u7740\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 await \u4ee5\u53ca\u5bf9 Promise.all() \u65b9\u6cd5\u7684\u8c03\u7528\u3002<\/p>\n<p>\u552f\u4e00\u8981\u8bb0\u4f4f\u7684\u662f\uff0c\u7531\u4e8e await \u4ec5\u5728\u5f02\u6b65\u51fd\u6570\u548c\u6a21\u5757\u5185\u6709\u6548\uff0c\u56e0\u6b64\u6211\u4eec\u5fc5\u987b\u5c06\u4ee3\u7801\u5305\u88c5\u5728\u5f02\u6b65\u51fd\u6570\u5185\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>function create_promise(data, duration) {\n  return new Promise((resolve) =&amp;gt; {\n    setTimeout(() =&amp;gt; {\n      resolve(data);\n    }, duration);\n  });\n}\n\nconst promise_a = create_promise(\"Loaded Textures\", 3000);\nconst promise_b = create_promise(\"Loaded Music\", 2000);\nconst promise_c = create_promise(\"Loaded Dialogue\", 4000);\n\nconst my_promises = [promise_a, promise_b, promise_c];\n\nasync function result_from_promises(promises) {\n  let loading_status = await Promise.all(promises);\n  console.log(loading_status);\n}\n\nresult_from_promises(my_promises);\n\n\/* Outputs\n\n08:50:43 Hello, Promises!\n08:50:47 Array(3) [ \"Loaded Textures\", \"Loaded Music\", \"Loaded Dialogue\" ]\n\n*\/\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u4e00\u6b21\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3a create_promise() \u7684\u51fd\u6570\uff0c\u5b83\u6839\u636e\u63d0\u4f9b\u7684\u6570\u636e\u548c\u6301\u7eed\u65f6\u95f4\u4e3a\u6211\u4eec\u521b\u5efa\u627f\u8bfa\u3002\u6211\u4eec\u7684\u5f02\u6b65 result_from_promises() \u51fd\u6570\u4f7f\u7528 await \u5173\u952e\u5b57\u6765\u7b49\u5f85 Promise \u89e3\u6790\u3002<\/p>\n<h2>\u4f7f\u7528 Promise.allSettled() \u65b9\u6cd5<\/h2>\n<p>\u5f53\u60a8\u53ea\u60f3\u5728\u6240\u6709\u627f\u8bfa\u6210\u529f\u89e3\u51b3\u540e\u7ee7\u7eed\u64cd\u4f5c\u65f6\uff0c\u4f7f\u7528 Promise.all() \u65b9\u6cd5\u662f\u6709\u610f\u4e49\u7684\u3002\u4f8b\u5982\uff0c\u5f53\u60a8\u52a0\u8f7d\u6e38\u620f\u8d44\u6e90\u65f6\uff0c\u8fd9\u53ef\u80fd\u5f88\u6709\u7528\u3002<\/p>\n<p>\u4f46\u662f\uff0c\u5047\u8bbe\u60a8\u6b63\u5728\u83b7\u53d6\u6709\u5173\u4e0d\u540c\u57ce\u5e02\u5929\u6c14\u7684\u4fe1\u606f\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u60a8\u53ef\u4ee5\u8f93\u51fa\u83b7\u53d6\u6570\u636e\u6210\u529f\u7684\u6240\u6709\u57ce\u5e02\u7684\u5929\u6c14\u4fe1\u606f\uff0c\u5e76\u8f93\u51fa\u83b7\u53d6\u6570\u636e\u5931\u8d25\u7684\u9519\u8bef\u6d88\u606f\u3002<\/p>\n<p>Promise.allSettled() \u65b9\u6cd5\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\u6548\u679c\u6700\u597d\u3002\u6b64\u65b9\u6cd5\u7b49\u5f85\u6240\u6709\u901a\u8fc7\u7684\u627f\u8bfa\u901a\u8fc7\u51b3\u8bae\u6216\u62d2\u7edd\u6765\u89e3\u51b3\u3002\u6b64\u65b9\u6cd5\u8fd4\u56de\u7684 Promise \u5305\u542b\u4e00\u4e2a\u5bf9\u8c61\u6570\u7ec4\uff0c\u5176\u4e2d\u5305\u542b\u6709\u5173\u6bcf\u4e2a Promise \u7ed3\u679c\u7684\u4fe1\u606f\u3002<\/p>\n<pre>function create_promise(city) {\n  let random_number = Math.random();\n  \n  let duration = Math.floor(Math.random()*5)*1000;\n\n  return new Promise((resolve, reject) =&amp;gt; {\n    if (random_number  {\n        resolve(`Show weather in ${city}`);\n      }, duration);\n    } else {\n      setTimeout(() =&amp;gt; {\n        reject(`Data unavailable for ${city}`);\n      }, duration);\n    }\n  });\n}\n\nconst promise_a = create_promise(\"Delhi\");\nconst promise_b = create_promise(\"London\");\nconst promise_c = create_promise(\"Sydney\");\n\nconst my_promises = [create_promise(\"Delhi\"), create_promise(\"London\"), create_promise(\"Sydney\"), create_promise(\"Rome\"), create_promise(\"Las Vegas\")];\n\nasync function result_from_promises(promises) {\n  let loading_status = await Promise.allSettled(promises);\n  console.log(loading_status);\n}\n\nresult_from_promises(my_promises);\n\n\/* Outputs\n\n[\n  {\n    \"status\": \"fulfilled\",\n    \"value\": \"Show weather in Delhi\"\n  },\n  {\n    \"status\": \"fulfilled\",\n    \"value\": \"Show weather in London\"\n  },\n  {\n    \"status\": \"fulfilled\",\n    \"value\": \"Show weather in Sydney\"\n  },\n  {\n    \"status\": \"rejected\",\n    \"reason\": \"Data unavailable for Rome\"\n  },\n  {\n    \"status\": \"fulfilled\",\n    \"value\": \"Show weather in Las Vegas\"\n  }\n]\n\n*\/\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5982\u60a8\u6240\u89c1\uff0c\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5bf9\u8c61\u90fd\u5305\u542b\u4e00\u4e2a status \u5c5e\u6027\uff0c\u8ba9\u6211\u4eec\u77e5\u9053\u627f\u8bfa\u662f\u5426\u5df2\u5b9e\u73b0\u6216\u88ab\u62d2\u7edd\u3002\u5728\u5c65\u884c\u627f\u8bfa\u7684\u60c5\u51b5\u4e0b\uff0c\u5b83\u5305\u542b value \u5c5e\u6027\u4e2d\u7684\u89e3\u6790\u503c\u3002\u5728\u88ab\u62d2\u7edd\u7684 Promise \u7684\u60c5\u51b5\u4e0b\uff0c\u5b83\u5728 reason \u5c5e\u6027\u4e2d\u5305\u542b\u62d2\u7edd\u7684\u539f\u56e0\u3002<\/p>\n<h2>\u6700\u7ec8\u60f3\u6cd5<\/h2>\n<p>\u6211\u4eec\u4e86\u89e3\u4e86 Promise \u7c7b\u7684\u4e24\u4e2a\u6709\u7528\u65b9\u6cd5\uff0c\u5b83\u4eec\u53ef\u4ee5\u8ba9\u60a8\u540c\u65f6\u5904\u7406\u591a\u4e2a Promise\u3002\u5f53\u60a8\u60f3\u8981\u5728\u5176\u4e2d\u4e00\u4e2a Promise \u88ab\u62d2\u7edd\u540e\u7acb\u5373\u505c\u6b62\u7b49\u5f85\u5176\u4ed6 Promise \u89e3\u51b3\u65f6\uff0c Promise.all() \u65b9\u6cd5\u5f88\u6709\u7528\u3002\u5f53\u60a8\u60f3\u8981\u7b49\u5f85\u6240\u6709\u627f\u8bfa\u89e3\u51b3\u65f6\uff0c\u65e0\u8bba\u5176\u89e3\u51b3\u6216\u62d2\u7edd\u72b6\u6001\u5982\u4f55\uff0c Promise.allSettled() \u65b9\u6cd5\u975e\u5e38\u6709\u7528\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fJavaScript\u4e2d\u4f7f\u7528Promise.all()\u548cPromise.allSettled()\u65b9\u6cd5\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6559\u7a0b\u5c06\u6559\u60a8\u5982\u4f55\u5728 JavaScript \u4e2d\u4f7f\u7528 Promise \u7b49\u5f85\u3002 \u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u5c06\u6559\u60a8\u6709\u5173 Promise.all() \u548c Promise.allSettled() \u65b9\u6cd5\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u5b83\u4eec\u6765\u5904\u7406\u591a\u4e2a Promise\u3002 \u4f7f\u7528 Promise.all() \u65b9\u6cd5 Promise \u5bf9\u8c61\u5177\u6709\u4e09\u4e2a\u6709\u7528\u7684\u65b9\u6cd5\uff0c\u540d\u4e3a then()\u3001catch() \u548c finally()\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u5b83\u4eec\u5728 Promise \u5b8c\u6210\u65f6\u6267\u884c\u56de\u8c03\u65b9\u6cd5\u3002 p&gt; Promise.all() \u65b9\u6cd5\u662f\u4e00\u4e2a\u9759\u6001\u65b9\u6cd5\uff0c\u8fd9\u610f\u5473\u7740\u5b83\u5c5e\u4e8e\u6574\u4e2a\u7c7b\uff0c\u800c\u4e0d\u662f\u7ed1\u5b9a\u5230\u8be5\u7c7b\u7684\u4efb\u4f55\u7279\u5b9a\u5b9e\u4f8b\u3002\u5b83\u63a5\u53d7\u53ef\u8fed\u4ee3\u7684 Promise \u4f5c\u4e3a\u8f93\u5165\u5e76\u8fd4\u56de\u5355\u4e2a Promise \u5bf9\u8c61\u3002 \u6b63\u5982\u6211\u4e4b\u524d\u63d0\u5230\u7684\uff0cPromise.all() \u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684 Promise\u3002\u5982\u679c\u4f20\u9012\u7ed9\u8be5\u65b9\u6cd5\u7684\u6240\u6709\u627f\u8bfa\u90fd\u5df2\u6210\u529f\u89e3\u6790\uff0c\u5219\u6b64\u65b0\u627f\u8bfa\u5c06\u89e3\u6790\u4e3a\u5df2\u786e\u5b9a\u627f\u8bfa\u503c\u7684\u6570\u7ec4\u3002\u4e00\u65e6\u901a\u8fc7\u7684\u627f\u8bfa\u4e4b\u4e00\u88ab\u62d2\u7edd\uff0c\u8fd9\u4e2a\u65b0\u7684\u627f\u8bfa\u4e5f\u5c06\u88ab\u62d2\u7edd\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u6240\u6709 Promise \u5747\u6210\u529f\u89e3\u51b3 \u4ee5\u4e0b\u662f Promise.all() \u65b9\u6cd5\u7684\u793a\u4f8b\uff0c\u5176\u4e2d\u6240\u6709 Promise \u5747\u5df2\u6210\u529f\u89e3\u6790\uff1a const promise_a = new Promise((resolve) =&amp;gt; { setTimeout(() =&amp;gt; { resolve(&#8216;Loaded Textures&#8217;); }, 3000); }); [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-32396","post","type-post","status-publish","format-standard","hentry","category-cms"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32396","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=32396"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32396\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=32396"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=32396"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=32396"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}