{"id":2995,"date":"2025-11-21T21:40:58","date_gmt":"2025-11-21T13:40:58","guid":{"rendered":"https:\/\/www.xfan.top\/?p=2995"},"modified":"2025-11-21T21:40:58","modified_gmt":"2025-11-21T13:40:58","slug":"%e5%89%8d%e7%ab%af%e5%85%a8%e5%b1%80%e5%85%b1%e4%ba%ab%e8%b5%84%e6%ba%90%e5%b9%b6%e5%8f%91%e5%90%88%e5%b9%b6%e5%8a%a0%e8%bd%bd%ef%bc%88%e9%80%82%e7%94%a8%e4%ba%8e%e5%85%a8%e5%b1%80%e7%8a%b6%e6%80%81","status":"publish","type":"post","link":"https:\/\/www.xfan.top\/index.php\/2025\/11\/21\/2995\/","title":{"rendered":"\u524d\u7aef\u5168\u5c40\u5171\u4eab\u8d44\u6e90\u5e76\u53d1\u5408\u5e76\u52a0\u8f7d\uff08\u9002\u7528\u4e8e\u5168\u5c40\u72b6\u6001\u5b58\u50a8\uff09"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>async function getSomething() {}\n\nlet global_something\nlet fetching = false\n\nconst callbacks = &#91;]\n\nfunction updateSomething() {\n  return new Promise&lt;void&gt;((resolve) =&gt; {\n    if (fetching) {\n      callbacks.push(() =&gt; resolve())\n      return\n    }\n    fetching = true\n\n    getSomething()\n      .then((data) =&gt; {\n        global_something = data\n      })\n      .finally(() =&gt; {\n        fetching = false\n        resolve()\n        callbacks.forEach((callback) =&gt; callback())\n        callbacks.length = 0\n      })\n  })\n}<\/code><\/pre>\n\n\n\n<p>\u9002\u7528\u4e8e\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u591a\u4e2a\u5730\u65b9\u540c\u65f6\u8bf7\u6c42\u540c\u4e00\u4e2a\u5168\u5c40\u8d44\u6e90<\/li>\n\n\n\n<li>\u9700\u8981\u907f\u514d\u5e76\u53d1\u91cd\u590d\u8bf7\u6c42<\/li>\n\n\n\n<li>\u7b2c\u4e00\u6b21\u8bf7\u6c42\u672a\u5b8c\u6210\u65f6\uff0c\u5176\u5b83 await \u90fd\u8981\u6302\u8d77\u7b49\u5f85<\/li>\n\n\n\n<li>\u8bf7\u6c42\u5b8c\u6210\u540e\u6240\u6709\u7b49\u5f85\u8005\u90fd\u8981 resolve<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u9002\u7528\u4e8e\uff1a<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,18,20],"tags":[],"class_list":["post-2995","post","type-post","status-publish","format-standard","hentry","category-jsts","category-webappdev","category-fed"],"_links":{"self":[{"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/posts\/2995","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/comments?post=2995"}],"version-history":[{"count":3,"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/posts\/2995\/revisions"}],"predecessor-version":[{"id":3000,"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/posts\/2995\/revisions\/3000"}],"wp:attachment":[{"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/media?parent=2995"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/categories?post=2995"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/tags?post=2995"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}