{"id":84406,"date":"2020-05-14T10:28:22","date_gmt":"2020-05-14T02:28:22","guid":{"rendered":"http:\/\/4563.org\/?p=84406"},"modified":"2020-05-14T10:28:22","modified_gmt":"2020-05-14T02:28:22","slug":"%e6%9c%89%e6%b2%a1%e6%9c%89%e6%8a%8a-promise-generator-%e5%92%8c-async-await-%e4%b9%8b%e9%97%b4%e7%9a%84%e5%85%b3%e7%b3%bb%e8%ae%b2%e8%a7%a3%e5%be%97%e6%af%94%e8%be%83%e6%b8%85%e6%a5%9a%e6%9d%a1","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=84406","title":{"rendered":"\u6709\u6ca1\u6709\u628a Promise, Generator, \u548c async\/await \u4e4b\u95f4\u7684\u5173\u7cfb\u8bb2\u89e3\u5f97\u6bd4\u8f83\u6e05\u695a\u6761\u7406\u7684\u6587\u7ae0\u6216\u8005\u535a\u5ba2\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u6709\u6ca1\u6709\u628a Promise, Generator, \u548c async\/await \u4e4b\u95f4\u7684\u5173\u7cfb\u8bb2\u89e3\u5f97\u6bd4\u8f83\u6e05\u695a\u6761\u7406\u7684\u6587\u7ae0\u6216\u8005\u535a\u5ba2\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : yazoox <\/span>  <span><i><\/i> 6<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u5982\u679c\uff0c\u6b63\u5728\u5b66\u4e60\u524d\u7aef\u5f00\u53d1\u3002\u5bf9\u8fd9\u51e0\u5757\u6709\u70b9\u8ff7\u7cca\u3002<\/p>\n<p>\u611f\u89c9\u597d\u50cf\u662f \u5148\u6709 Promise, \u518d\u6709 generator\uff0c\u7136\u540e\u73b0\u5728\u53c8\u6709\u4e86 async\/await<\/p>\n<p>\u597d\u50cf\u8d8a\u6765\u8d8a\u201c\u5148\u8fdb\u201d\u548c\u201c\u7b80\u5355\u201d\u3002<\/p>\n<p>\u6709\u6ca1\u6709\u5bf9\u8fd9\u4e09\u8005\u7684\u7406\u89e3 \/\u89e3\u6790\u6bd4\u8f83\u597d\u7684\u6587\u7ae0\u6216\u8005\u535a\u5ba2\uff0c\u60f3\u7406\u89e3\u5f97\u66f4\u6df1\u5165\u4e00\u4e9b\uff1f<\/p>\n<p>\u8c22\u8c22\uff01<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>28<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"1484812\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : woodensail <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5148\u6709 promise\uff0c\u89e3\u51b3\u4e86\u56de\u8c03\u5730\u72f1\u7684\u95ee\u9898\u3002\u4f46\u662f\u526f\u4f5c\u7528\u662f\u4e00\u6bb5\u903b\u8f91\u88ab\u5207\u5206\u5230\u591a\u4e2a\u4f5c\u7528\u57df\u4e2d\uff0c\u4e14 return \u548c\u5f02\u5e38\u90fd\u88ab\u62e6\u622a\u3002\u56e0\u4e3a\u672c\u8d28\u4e0a js \u4e00\u4e2a\u51fd\u6570\u5fc5\u987b\u540c\u6b65\u6267\u884c\u5b8c\u6bd5\uff0c\u60f3\u5b9e\u73b0\u5f02\u6b65\u53ea\u80fd\u7528\u591a\u4e2a\u51fd\u6570\u6765\u5b9e\u73b0\u3002<\/p>\n<p>\u7136\u540e\u6709\u4e86 generator\uff0cgenerator \u7684\u521b\u4e3e\u5728\u4e8e\u5141\u8bb8\u4e00\u4e2a\u51fd\u6570\u6267\u884c\u5230\u4e00\u534a\u6302\u8d77\uff0c\u7b49\u5f02\u6b65\u56de\u8c03\u540e\u7ee7\u7eed\u6267\u884c\uff0c\u5b8c\u7f8e\u7684\u89e3\u51b3\u4e86 promise \u5e26\u6765\u7684\u526f\u4f5c\u7528\u3002<\/p>\n<p>\u800c async\/await \u672c\u8d28\u4e0a\u662f generator \u5728\u7279\u6b8a\u573a\u666f\u4e0b\u4f7f\u7528\u65f6\u7684\u4e00\u4e2a\u8bed\u6cd5\u7cd6\u800c\u5df2\uff0c\u7701\u5f97\u4f60\u53bb\u4f9d\u8d56 co \u6a21\u5757\u4e86\u3002<\/p>\n<p>\u81f3\u4e8e\u6587\u7ae0\u624b\u5934\u8fd8\u771f\u6ca1\u6709\uff0c\u6bd5\u7adf\u4e5f\u662f\u5f88\u8001\u7684\u4e1c\u897f\u4e86\u2026\u2026                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1484813\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ClericPy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5e73\u65f6\u9047\u5230\u95ee\u9898\u90fd\u76f4\u63a5\u770b MDN \u7684, \u975e\u8981\u627e\u6559\u7a0b\u7684\u8bdd, <\/p>\n<p>\u73b0\u4ee3 JavaScript \u6559\u7a0b &#8211; https:\/\/zh.javascript.info\/<\/p>\n<p>\u662f\u6211\u4e4b\u524d\u770b\u7684, \u611f\u89c9\u6709\u70b9\u5176\u4ed6\u8bed\u8a00\u57fa\u7840, \u7406\u89e3\u8d77\u6765\u5e94\u8be5\u4e0d\u8d39\u52b2, \u81f3\u4e8e\u66f4\u6df1\u5165&#8230; \u5f97\u770b\u60f3\u591a\u6df1\u4e86                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1484814\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : woodensail <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u53e6\u5916\u518d\u8bf4\u4e0b\u5173\u4e8e\u8bed\u6cd5\u7cd6\u7684\u95ee\u9898\uff0c\u6211\u4e00\u822c\u628a async\/await \u770b\u505a generator\uff0c\u56e0\u4e3a async\/await \u6838\u5fc3\u7684\u5f02\u6b65\u6302\u8d77\u548c\u4f5c\u7528\u57df\u4fdd\u6301\u529f\u80fd\u5df2\u7ecf\u5728 generator \u5b9e\u73b0\u4e86\uff0c\u5c31\u7b97\u6ca1\u6709 async\/await\uff0c\u8981\u4e0d\u4e86\u591a\u5c11\u4ee3\u7801\u4e5f\u80fd\u5c01\u88c5\u7c7b\u4f3c\u7684\u529f\u80fd\u51fa\u6765\u3002<\/p>\n<p>\u800c promise \u5230 generator \u867d\u7136\u4e5f\u80fd\u901a\u8fc7 regenerator \u7684\u65b9\u5f0f\u6765\u5b9e\u73b0\uff0c\u4f46\u662f\u7f3a\u5c11\u4f5c\u7528\u57df\u4fdd\u6301\u548c\u5f02\u6b65\u6302\u8d77\u3002<br \/>\u53ea\u80fd\u901a\u8fc7\u5957\u4e00\u4e2a\u51fd\u6570\u4fdd\u6301\u4f5c\u7528\u57df\uff0c\u7136\u540e\u591a\u6b21\u8c03\u7528\u540c\u4e00\u4e2a\u65b9\u6cd5\uff0c\u901a\u8fc7 switch case \u65b9\u5f0f\u6765\u5206\u7247\u6267\u884c\u3002\u800c\u4f60\u7684\u539f\u59cb\u4ee3\u7801\u4e5f\u88ab\u7f16\u8bd1\u5f97\u9762\u76ee\u5168\u975e\u3002\u662f\u4e2a\u975e\u5e38\u4e0d\u4f18\u96c5\u7684 hack \u624b\u6bb5\u3002\u8fdc\u4e0d\u5982\u539f\u751f\u7684 generator \u597d\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1484815\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : noobsheldon <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             Angular Observable                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1484816\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : kidlj <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u962e\u4e00\u5cf0\u6709\u4e00\u7cfb\u5217\u51e0\u7bc7\u535a\u5ba2\uff0c\u4ece\u56de\u8c03\uff0c\u51fd\u6570\u79d1\u91cc\u5316\uff0c\u8bb2\u5230 promise\uff0c\u8fc7\u6e21\u671f\u7684 co \u5e93\u7684\u5b9e\u73b0\uff0c\u7136\u540e\u5230 async\/await. \u975e\u5e38\u4e0d\u9519\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1484817\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : sunjourney <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @woodensail #3 \u53c8\u662f\u4e00\u4e2a\u962e\u4e00\u5cf0\u6587\u7ae0\u7684\u53d7\u5bb3\u8005                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1484818\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : helloSpringBoot <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             https:\/\/juejin.im\/post\/5b04c7db6fb9a07aa542a772                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1484819\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lizheming <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             https:\/\/zhuanlan.zhihu.com\/p\/42649246 \u63a8\u8350\u4e0b\u8fd9\u7bc7                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1484820\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : CosimoZi <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             continuation \u7684\u4e0d\u540c\u8868\u73b0\u5f62\u5f0f\u800c\u5df2.\u4e07\u53d8\u4e0d\u79bb\u5176\u5b97.                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1484821\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : giuem <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             https:\/\/zhuanlan.zhihu.com\/p\/83965949 \u770b\u8fd9\u7bc7\u6587\u7ae0\u7684\u540e\u534a\u6bb5                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1484822\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : JayLin1011 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u53ef\u4ee5\u770b\u4e00\u4e0b\u962e\u4e00\u5cf0\u8001\u5e2b\u7684\u6559\u7a0b\uff0c\u6df1\u5165\u6dfa\u51fa\u7570\u6b65\u7de8\u7a0b=\u3002=                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1484823\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zhuowenli <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u300a\u4f60\u4e0d\u77e5\u9053\u7684 JavaScript \u300b\u4e2d\u5377                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1484824\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : mxT52CRuqR6o5 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             Promide \u641e\u660e\u767d\uff0casync\/await \u81ea\u7136\u5c31\u660e\u767d\u4e86\uff0casync\/await \u662f promise \u7684\u8bed\u6cd5\u7cd6                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1484825\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : autoxbc <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5c3d\u7ba1 Babel \u7684 async\/await \u662f\u57fa\u4e8e\u751f\u6210\u5668\u5b9e\u73b0\u7684\uff0c\u7136\u800c\u5728\u903b\u8f91\u5173\u7cfb\u4e0a\uff0c\u5b8c\u5168\u53ef\u4ee5\u7565\u8fc7\u751f\u6210\u5668\uff0c\u4ece Promise \u76f4\u63a5\u5230 async\/await<\/p>\n<p>\u5b66\u4e60\u8def\u5f84\u662f<br \/>1. \u5f7b\u5e95\u4e86\u89e3 Promise \u7684\u5de5\u4f5c\u903b\u8f91\uff0c\u6ce8\u610f\u5de5\u4f5c\u903b\u8f91\u4e0d\u662f\u5b9e\u73b0\u7ec6\u8282<br \/>http:\/\/liubin.org\/promises-book\/<\/p>\n<p>2. async\/await \u5b8c\u5168\u5f53\u6210 Promise \u7684\u8bed\u6cd5\u7cd6<br \/>async \u5c31\u662f\u5728\u5305\u88c5 Promise\uff0cawait \u5c31\u662f\u89e3\u5f00 Promise                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1484826\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ysc3839 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @woodensail Promise \u6ca1\u89e3\u51b3\u56de\u8c03\u5730\u72f1\uff0c\u4f20\u9012\u7ed9 Promise then \u7684\u8fd8\u662f\u4e00\u4e2a\u4e2a\u56de\u8c03\u51fd\u6570\u3002async function \u624d\u89e3\u51b3\u4e86\u3002<br \/>\u6309\u7167\u6211\u7684\u7406\u89e3\uff0cPromise \u662f\u63d0\u4f9b\u4e86\u4e00\u4e2a\u901a\u7528\u7684\u5f02\u6b65\u56de\u8c03\u548c\u8fd4\u56de\u503c\u7684\u5de5\u5177\u5e93\u3002\u6ca1\u6709 Promise \u7684\u65f6\u5019\uff0c\u5f02\u6b65\u56de\u8c03\u4e00\u822c\u662f\u628a\u56de\u8c03\u51fd\u6570\u4f5c\u4e3a\u51fd\u6570\u53c2\u6570\u4f20\u9012\u8fdb\u53bb\uff0c\u4e0d\u540c\u5e93\u7684\u63a5\u53e3\u5404\u4e0d\u76f8\u540c\u3002\u6709\u4e86 Promise \u4e4b\u540e\uff0c\u5927\u5bb6\u90fd\u53ef\u4ee5\u7528\u4e00\u4e2a\u7edf\u4e00\u7684\u63a5\u53e3\uff0c\u53ef\u4ee5\u7b80\u5316\u5f00\u53d1\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1484827\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ciaoly <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @sunjourney \u4f55\u4ee5\u51fa\u6b64\u8a00\uff1f\u962e\u4e00\u5cf0\u7684\u535a\u5ba2\u5199\u7684\u4e0d\u5bf9\u5417\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1484828\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : chengzi168 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @sunjourney \u6c42\u89e3\u91ca\uff0c\u962e\u4e00\u5cf0\u7684\u6587\u7ae0\u4e0d\u5bf9\u4e48\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1484829\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : woodensail <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ysc3839 \u989d\uff0c\u90a3\u662f\u4f60\u7528\u6cd5\u4e0d\u5bf9\uff0cpromise \u7684\u6b63\u786e\u7528\u6cd5\u662f fun1().then(fun2).then(fun3)\u8fd9\u6837\uff0c\u65e0\u8bba\u591a\u5c11\u4e2a\u5f02\u6b65\u64cd\u4f5c\uff0c\u53ea\u9700\u8981\u4e00\u5c42\u56de\u8c03\u5373\u53ef\u3002\u7f3a\u70b9\u5c31\u662f\u4e0a\u9762\u8bf4\u7684\u4f60\u6ca1\u6cd5\u76f4\u63a5 return\uff0c\u60f3 rutern \u5c31\u53ea\u80fd\u629b\u5f02\u5e38\uff0c\u7136\u540e\u5c31\u628a\u5f02\u5e38\u4fe1\u606f\u6c61\u67d3\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1484830\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ysc3839 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @woodensail \u6211\u77e5\u9053\u662f\u8fd9\u6837\u4e00\u4e2a\u4e2a then\uff0c\u4f46\u662f\u8fd8\u662f\u628a\u6574\u4e2a\u4ee3\u7801\u903b\u8f91\u62c6\u5206\u6210\u4e86\u4e00\u4e2a\u4e2a\u56de\u8c03\u51fd\u6570\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1484831\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : woodensail <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @sunjourney \u90a3\u5565\uff0c\u4e0d\u77e5\u9053\u4f60\u4e3a\u4ec0\u4e48\u4f1a\u8fd9\u4e48\u8ba4\u4e3a\uff0c\u4f46\u662f\u6211\u786e\u5b9e\u6ca1\u8bfb\u8fc7\u4ed6\u7684\u6587\u7ae0                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1484832\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ysc3839 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @woodensail \u800c\u4e14\u4e0d\u5bf9\u5440\uff0c\u8fd9\u662f\u9488\u5bf9\u4e00\u4e2a Promise \u7684\u60c5\u51b5\uff0c\u5047\u5982\u7b2c\u4e00\u4e2a Promise \u6267\u884c\u6210\u529f\u4e86\uff0c\u8981\u6267\u884c\u53e6\u4e00\u4e2a Promise\uff0c\u8fd8\u662f\u4f1a\u53d8\u6210\u90a3\u79cd\u56de\u8c03\u5d4c\u5957\u7684\u60c5\u51b5\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1484833\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : woodensail <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ysc3839 \u662f\u7684\u554a\uff0c\u6211\u4e0a\u9762\u4e5f\u8bf4\u4e86\uff0cpromise \u5728\u89e3\u51b3\u56de\u8c03\u5730\u72f1\u540e\u4e5f\u5e26\u6765\u4e86\u4f5c\u7528\u57df\u5206\u88c2\uff0c\u6d41\u7a0b\u63a7\u5236\u56f0\u96be\u7b49\u65b0\u7684\u95ee\u9898\uff0c\u4e0d\u662f\u4e2a\u5b8c\u7f8e\u7684\u89e3\u51b3\u65b9\u6848\u3002\u76f4\u5230 generator \u8bde\u751f\u624d\u5f7b\u5e95\u89e3\u51b3\u4e86\u95ee\u9898\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1484834\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : woodensail <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ysc3839 \u4f60\u770b\u6211\u5199\u7684\uff0cthen \u662f\u53ef\u4ee5\u94fe\u5f0f\u8c03\u7528\u7684\uff0cfun1().then(fun2).then(fun3).then(fun4).then(fun5)<br \/>\u53ea\u989d\u5916\u5305\u4e86\u4e00\u5c42\u800c\u5df2\u3002<br \/>\u4e0d\u4f1a\u51fa\u73b0\u56de\u8c03\u5730\u72f1\u90a3\u6837\u5de6\u8fb9 tab \u534a\u4e2a\u5c4f\u5e55\u7684\u60c5\u51b5\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1484835\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : woodensail <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ysc3839 @ysc3839 \u63a5\u4e0a\u9762\u90a3\u4e2a\u4f8b\u5b50\u8bf4\u4e0b promise \u89e3\u51b3\u56de\u8c03\u5730\u72f1\u540e\u5e26\u6765\u7684\u65b0\u95ee\u9898\u3002<\/p>\n<p>1\uff1a\u4f5c\u7528\u57df\u5206\u88c2\uff0c\u6bd4\u5982 fun3 \u4e2d\u8bf7\u6c42\u7684\u5f97\u5230\u7684\u7ed3\u679c\u5728 fun4 \u8981\u4f7f\u7528\uff0c\u4f46\u662f\u76f4\u63a5\u5728 fun3 \u548c 4 \u7684\u4f5c\u7528\u57df\u4e0d\u662f\u540c\u4e00\u4e2a\u3002\u6240\u4ee5\u76f4\u63a5\u5728 fun3 \u4e2d\u5b9a\u4e49\u53d8\u91cf\u65e0\u6548\uff0c\u5fc5\u987b\u628a\u53d8\u91cf\u58f0\u660e\u63d0\u524d\u5230 fun1 \u6267\u884c\u4e4b\u524d\u3002<\/p>\n<p>2\uff1a\u6d41\u7a0b\u63a7\u5236\u56f0\u96be\uff0c\u6bd4\u5982 fun2 \u4e2d\u8bf7\u6c42\u7ed3\u679c\u663e\u793a\u6d41\u7a0b\u4e0d\u80fd\u7ee7\u7eed\u6267\u884c\uff0c\u9700\u8981\u9000\u51fa\u3002<br \/>\u8fd9\u65f6\u5019\u6ca1\u6cd5\u8df3\u8fc7 345 \u7684\u6267\u884c\uff0c\u8981\u4e48 fun2 \u901a\u8fc7\u53d8\u91cf\u6216\u8fd4\u56de\u503c\u6765\u901a\u77e5\uff0c\u5728 345 \u7684\u5f00\u5934\u5206\u522b\u5224\u65ad\u4e00\u4e0b\u6807\u5fd7\uff0c\u6709\u6807\u5fd7\u5c31\u76f4\u63a5\u9000\u51fa\u3002<br \/>\u6216\u8005\u76f4\u63a5\u629b\u5f02\u5e38\u6765\u8df3\u8fc7\u540e\u9762\u7684\u6b65\u9aa4\uff0c\u4f46\u8fd9\u6837\u4e00\u6837\uff0c\u4e1a\u52a1\u6d41\u7a0b\u5c31\u548c\u771f\u6b63\u7684\u5f02\u5e38\u6df7\u5728\u4e86\u4e00\u8d77\uff0c\u7ed9\u5f02\u5e38\u6cbb\u7406\u5e26\u6765\u4e86\u9ebb\u70e6\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1484836\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ysc3839 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @woodensail \u67e5\u4e86\u4e0b\u6587\u6863\uff0c\u662f\u6211\u5b64\u964b\u5be1\u95fb\u4e86\u3002then \u7684\u56de\u8c03\u51fd\u6570\u53ef\u4ee5\u8fd4\u56de\u4e00\u4e2a Promise\uff0c\u4e0b\u4e00\u4e2a then \u7684\u56de\u8c03\u5c31\u4f1a\u5728\u8fd4\u56de\u7684\u90a3\u4e2a Promise \u5b8c\u6210\u65f6\u88ab\u8c03\u7528\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1484837\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : woodensail <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ysc3839 \u55ef\uff0c\u6211\u5f53\u5e74\u521a\u77e5\u9053 promise \u8fd9\u4e2a\u7279\u6027\u7684\u65f6\u5019\u975e\u5e38\u5174\u594b\uff0c\u7136\u540e\u5f88\u5feb\u5c31\u88ab\u4e1a\u52a1\u6559\u505a\u4eba\u4e86\u3002<br \/>\u4e00\u4e2a\u533b\u4fdd\u7684\u4e1a\u52a1\uff0c\u9700\u8981<br \/>1\uff1a\u8bbf\u95ee\u81ea\u5bb6\u670d\u52a1\u5668\u83b7\u53d6\u8ba2\u5355\u4fe1\u606f(\u5305\u542b\u591a\u4e2a\u8d26\u5355)<br \/>2\uff1a\u8bbf\u95ee\u533b\u4fdd\u670d\u52a1\u5668\u505a\u9884\u7ed3\u7b97<br \/>4\uff1a\u5faa\u73af\u8bbf\u95ee\u533b\u4fdd\u670d\u52a1\u5668\uff0c\u4e00\u4e2a\u4e00\u4e2a\u521b\u5efa\u8d26\u5355<br \/>3\uff1a\u8bbf\u95ee\u81ea\u5bb6\u670d\u52a1\u5668\u8bb0\u5f55\u8d26\u5355<br \/>5\uff1a\u5faa\u73af\u8bbf\u95ee\u533b\u4fdd\u670d\u52a1\u5668\uff0c\u4e00\u4e2a\u4e00\u4e2a\u786e\u8ba4\u8d26\u5355<br \/>5\uff1a\u8bbf\u95ee\u81ea\u5bb6\u670d\u52a1\u8bb0\u5f55\u7ed3\u679c<br \/>\u5176\u4e2d\u4efb\u4f55\u4e00\u6b65\u5931\u8d25\u90fd\u8981\u8df3\u8fc7\u540e\u7eed\u6b65\u9aa4\uff0c\u5e76\u4e14\u8bb0\u5f55\u5931\u8d25\u4fe1\u606f\u3002\u5982\u679c\u5931\u8d25\u65f6\u5df2\u7ecf\u6709\u90e8\u5206\u8d26\u5355\u88ab\u521b\u5efa\u9700\u8981\u8fdb\u884c\u53d6\u6d88\uff1b\u5982\u679c\u6709\u90e8\u5206\u8d26\u5355\u5df2\u7ecf\u786e\u8ba4\uff0c\u9700\u8981\u8fdb\u884c\u9000\u8d39\u3002<\/p>\n<p>\u6700\u540e\u7528\u76ae\u8089\u9762\u8272\u5199\u51fa\u6765\u4e00\u5768\u5c4e\u5c71\uff0c\u592a\u7edd\u671b\u4e86\uff0c\u8fc7\u53bb\u8fd9\u4e48\u591a\u5e74\uff0c\u6211\u90fd\u518d\u4e5f\u6ca1\u78b0\u5230\u8fc7\u8fd9\u5927\u7684\u5c4e\u5c71\u4e86                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1484838\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : yazoox <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @woodensail \u5144\u5f1f\uff0c\u65e2\u7136\u4f60\u89c9\u5f97 Promise \u4e0d\u80fd\u5f88\u597d\u5904\u7406\u8fd9\u4e2a\u201c\u533b\u4fdd\u201d\u95ee\u9898\u3002<br \/>\u65f6\u9694\u591a\u5e74\uff0c\u73b0\u5728\u6709\u4e86 async\/await \u4e86\uff0c\u80fd\u5426\u5f88\u6f02\u4eae\u7684\u89e3\u51b3\u5f53\u5e74\u7684\u8fd9\u4e2a\u95ee\u9898\u5462\uff1f<\/p>\n<p>\u6211\u89c9\u5f97\u8fd9\u4e2a\u95ee\u9898\u5f88\u503c\u5f97\u82b1\u70b9\u65f6\u95f4\u7814\u7a76\u4e00\u4e0b\u3002<\/p>\n<p>\u5982\u679c\u4f60\u6709\u7a7a\u7684\u8bdd\uff0c\u53ef\u80fd\u5206\u4eab\u7ed9\u6211\u4eec\u5927\u5bb6\u3002\uff08\u522b\u5fd8\u8bb0\u4e86 @\u6211\u4e00\u4e0b\uff09                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1484839\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : woodensail <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @yazoox \u540e\u6765\u6709\u60f3\u8fc7\uff0c\u4e0d\u8fc7\u5df2\u7ecf\u8df3\u69fd\u4e86\u4e5f\u5c31\u4e0d\u7ba1\u4e86\u3002\u5982\u679c\u7528 async \u7684\u8bdd\u6709\u51e0\u4e2a\u4f18\u52bf\uff0c\u9996\u5148\u6574\u4e2a\u6d41\u7a0b\u5728\u540c\u4e00\u4e2a\u65b9\u6cd5\u4e2d\uff0c\u53ef\u4ee5\u968f\u65f6 return \u9000\u51fa\u540e\u7eed\u6b65\u9aa4\uff0c\u5728\u626b\u5c3e\u5904\u7406\u65b9\u9762\u4f1a\u7b80\u5355\u5f88\u591a\u3002<br \/>\u53e6\u5916\u7531\u4e8e async \u4e2d\u53ef\u4ee5\u76f4\u63a5 for \u5faa\u73af\u6267\u884c\u5f02\u6b65\u8bed\u53e5\uff0c\u6240\u4ee5\u4e0d\u9700\u8981\u7528 promise \u8fed\u4ee3\u7684\u65b9\u5f0f\u6765\u987a\u5e8f\u6267\u884c\u6570\u7ec4\u4e2d\u7684\u4efb\u52a1\uff0c\u4e5f\u8ba9\u4ee3\u7801\u53ef\u8bfb\u6027\u5927\u5e45\u63d0\u9ad8\u3002<\/p>\n<p>\u6574\u4f53\u7684\u8bdd\u4f30\u8ba1\u5f00\u53d1\u96be\u5ea6\u4e0d\u5230\u539f\u6765\u7684\u4e00\u534a\uff0c\u4ee3\u7801\u91cf\u4e0b\u964d\u4e0d\u591a\u4f46\u662f\u53ef\u8bfb\u6027\u5927\u5e45\u63d0\u5347\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u6709\u6ca1\u6709\u628a Promise, Gen&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/84406"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=84406"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/84406\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=84406"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=84406"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=84406"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}