{"id":162065,"date":"2020-10-01T04:02:28","date_gmt":"2020-09-30T20:02:28","guid":{"rendered":"http:\/\/4563.org\/?p=162065"},"modified":"2020-10-01T04:02:28","modified_gmt":"2020-09-30T20:02:28","slug":"nodejs-%e5%a6%82%e4%bd%95%e5%90%8c%e6%97%b6%e9%ab%98%e6%80%a7%e8%83%bd%e7%9a%84%e5%8f%91%e9%80%81%e5%a4%9a%e4%b8%aa%e8%af%b7%e6%b1%82%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=162065","title":{"rendered":"nodejs \u5982\u4f55\u540c\u65f6\u9ad8\u6027\u80fd\u7684\u53d1\u9001\u591a\u4e2a\u8bf7\u6c42\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  nodejs \u5982\u4f55\u540c\u65f6\u9ad8\u6027\u80fd\u7684\u53d1\u9001\u591a\u4e2a\u8bf7\u6c42\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : weishijun14 <\/span>  <span><i><\/i> 0<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p><strong>\u8bf7\u6559\u4e00\u4e0b\uff0cnodejs \u4e0d\u662f\u80fd\u7528 http.get \u53d1\u9001\u8bf7\u6c42\u4e48\uff0c \u5047\u8bbe\u6211\u8981\u540c\u65f6\u53d1\u5341\u4e2a\u8bf7\u6c42\uff0c\u7528 http.get \u5e94\u8be5\u8981\u600e\u4e48\u5199\u6bd4\u8f83\u597d\uff1f \u6211\u81ea\u5df1\u77e5\u9053\u7684\u5c31\u662f\u7528 promise.all \uff0c \u4f46\u662f\u60f3\u77e5\u9053\u6709\u6ca1\u6709\u66f4\u52a0\u9ad8\u6027\u80fd\u7684\u5199\u6cd5 \/\uff1f<\/strong><\/p>\n<pre><code>\/\/ \u6211\u81ea\u5df1\u76ee\u524d\u7684\u5199\u6cd5\uff1a function fetchAll () {   http.get('url1').then();   http.get('url2').then();   http.get('url3').then();   http.get('url4').then();   ...   http.get('url10').then(); } \/\/ \u8fd9\u91cc\u7684\u5341\u4e2a\u8bf7\u6c42\u80af\u5b9a\u662f\u5e76\u884c\u4e0d\u963b\u585e\u7684\uff0c\u6240\u4ee5\u7528\u8d77\u6765\u5e76\u6ca1\u6709\u4ec0\u4e48\u5927\u95ee\u9898\u3002\u53ea\u662f\u8fd9\u6837\u770b\u8d77\u6765 \/\/ \u4e0d\u662f\u5f88\u4f18\u96c5\u3002\u4e5f\u4e0d\u77e5\u9053\u4f1a\u4e0d\u4f1a\u6709\u4ec0\u4e48\u6027\u80fd\u95ee\u9898\u3002 <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>4<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3522866\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : TomVista <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u628a.then();\u7684\u5185\u5bb9\u62c6\u51fa\u53bb,\u5199\u6210\u51fd\u6570,\u4e0d\u8981\u5728 fetchAll \u91cc\u653e\u4e00\u5806,\u5176\u4ed6\u6ca1\u4ec0\u4e48.<\/p>\n<p>\u8981\u4f18\u96c5\u7684\u8bdd,\u7528 node EventEmitter,\u62c6\u5206\u6210\u89c2\u5bdf\u8005\u6a21\u5f0f<\/p>\n<p>\u9ad8\u6027\u80fd,\u4e0d\u7528\u8003\u8651,\u51e0\u5341 \u51e0\u767e\u5e76\u53d1 http,\u4e00\u822c\u51fa\u95ee\u9898\u5728\u7f51\u7edc\u5e26\u5bbd\u4e0a,                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3522867\" 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>                                                             Promise.all \u5e94\u8be5\u662f\u6700\u4f18\u89e3\u3002<br \/>\u4f60\u76ee\u524d\u7684\u5199\u6cd5\uff0c\u662f\u56e0\u4e3a then \u91cc\u9762\u7684\u5904\u7406\u4ee3\u7801\u5b8c\u5168\u4e0d\u540c\u5417\uff1f\u5982\u679c\u662f\u4e0d\u540c\u7684\u8bdd\u90a3\u8fd9\u4e48\u5199\u4e5f\u6ca1\u4ec0\u4e48\u95ee\u9898\u4e86\u3002<br \/>\u8fd8\u6709\u8981\u8003\u8651\u7684\u662f\u4f7f\u7528\u7684 http \u5e93\u4f1a\u4e0d\u4f1a\u81ea\u52a8\u590d\u7528\u8fde\u63a5\u4ee5\u53ca\u662f\u5426\u652f\u6301 HTTP\/2 \u3002\u5047\u8bbe\u4f60\u8fd9\u91cc\u7684 url \u5168\u90fd\u662f\u540c\u4e00\u4e2a\u57df\u540d\uff0c\u6709\u7684 http \u5e93\u4f1a\u81ea\u52a8\u4f7f\u7528\u540c\u4e00\u4e2a TCP \u8fde\u63a5\uff0c\u6709\u7684\u8981\u4e3b\u52a8\u521b\u5efa\u4e00\u4e2a session \u5bf9\u8c61\u624d\u4f1a\u590d\u7528\u3002\u4f1a\u590d\u7528\u8fde\u63a5\u7684\u60c5\u51b5\u4e0b\uff0cHTTP\/1.x \u53ef\u80fd\u4f1a\u964d\u4f4e\u6027\u80fd\uff0c\u4f46 HTTP\/2 \u5219\u4f1a\u63d0\u9ad8\u6027\u80fd\u3002<br \/>\u8ffd\u6c42\u66f4\u9ad8\u6027\u80fd\u7684\u8bdd\u53ef\u80fd\u8981\u7528 C\/C++ \u5199\u6269\u5c55\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3522868\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : weishijun14 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @TomVista @ysc3839 <\/p>\n<p>\u611f\u8c22\u4e0a\u5927\u4f6c\u4eec\u7684\u89e3\u7b54\uff01<br \/>\u6309\u7167\u89e3\u7b54\u6765\u8bf4\u7684\u8bdd\uff0c\u5c31\u662f\u6ca1\u5565\u5927\u95ee\u9898\u4e86\u3002\u3002\u3002\u56e0\u4e3a\u76ee\u524d\u786e\u5b9e\u6ca1\u6709\u5f88\u5927\u91cf\u7684\u8bf7\u6c42\u3002\u3002\u6211\u5148\u8fd9\u4e48\u5199\u7740\u3002\u3002\u540e\u671f\u8981\u8c03\u6574\u7684\u65f6\u5019\u518d\u6765\u770b\u770b\u5927\u4f6c\u4eec\u7684\u65b9\u6cd5\u3002\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3522869\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zihuyishi <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u89c9\u5f97\u76f8\u5bf9\u4e8e http \u8bf7\u6c42\u672c\u8eab\u7684\u65f6\u95f4\uff0c\u8fd9\u91cc\u600e\u4e48\u5199\u5e94\u8be5\u90fd\u4e0d\u4f1a\u5f71\u54cd\u5230\u6027\u80fd\u5427\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>nodejs \u5982\u4f55\u540c\u65f6\u9ad8\u6027\u80fd\u7684\u53d1\u9001&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\/162065"}],"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=162065"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/162065\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=162065"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=162065"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=162065"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}