{"id":789,"date":"2019-02-15T21:25:41","date_gmt":"2019-02-15T13:25:41","guid":{"rendered":"https:\/\/sora.sound.moe\/?p=789"},"modified":"2019-02-15T21:25:41","modified_gmt":"2019-02-15T13:25:41","slug":"promise-race-%e5%ae%9e%e7%8e%b0-timeout-%e5%92%8c%e5%9d%91","status":"publish","type":"post","link":"https:\/\/sora.sound.moe\/?p=789","title":{"rendered":"Promise.race() \u5b9e\u73b0 Timeout \u2014\u2014\u548c\u5751"},"content":{"rendered":"\n<!--more-->\n\n\n\n<p>\u5728\u4f7f\u7528 axios \u8fdb\u884c\u4e0b\u8f7d\u7684\u65f6\u5019\uff0c\u7ecf\u5e38\u4f1a\u51fa\u73b0\u4e0b\u8f7d\u5230\u4e00\u534a\u5361\u4f4f\u7684\u60c5\u51b5\uff0c\u800c\u8fd9\u79cd\u60c5\u51b5 axios \u7684 timeout \u662f\u6ca1\u6709\u7528\u7684\uff0c\u4e8e\u662f\u4e4b\u524d\u4f7f\u7528\u4e86 Promise.race() \u6765\u5b9e\u73b0\u4e86\u4e00\u4e2a\u8d85\u65f6\u3002\u4e3b\u8981\u53c2\u8003\u7684\u662f<a href=\"https:\/\/italonascimento.github.io\/applying-a-timeout-to-your-promises\/ \">\u8fd9\u7bc7\u6587\u7ae0<\/a>\u3002<\/p>\n\n\n\n<p>\u4f46\u662f\u8fd9\u4e48\u4e00\u505a\u5c31\u53d1\u73b0\u4e86\u65b0\u7684\u95ee\u9898\u3002\u7528\u6765\u63a7\u5236\u8d85\u65f6\u7684 Promise \u88ab reject \u4e4b\u540e\uff0cPromise.race() \u7684\u53e6\u5916\u4e00\u8fb9\uff0c\u4e5f\u5c31\u662f\u63a7\u5236\u4e0b\u8f7d\u7684 Promise \u4ecd\u7136\u5728\u8fd0\u884c\uff0c\u9020\u6210\u4e86\u5185\u5b58\u6cc4\u6f0f\u3002<\/p>\n\n\n\n<p>\u4e5f\u5c31\u662f<a href=\"https:\/\/stackoverflow.com\/questions\/52782289\/nodejs-racing-a-promise-with-a-timeout-keeps-its-data-around-until-the-timeout\">\u8fd9\u4e2a\u95ee\u9898<\/a>\u63cf\u8ff0\u7684\u4e8b\u60c5\u3002<\/p>\n\n\n\n<p>\u5176\u5b9e\u95ee\u9898\u5c31\u662f\u53e6\u5916\u4e00\u4e2a Promise \u5fc5\u987b\u624b\u52a8 fulfill \u6216\u8005 reject \u3002\u4e8e\u662f\u8fd9\u91cc\u91c7\u7528 axios \u81ea\u5df1\u7684 cancel \u673a\u5236\u5b9e\u73b0\uff0c\u5728\u8d85\u65f6\u7684\u540c\u65f6\u628a\u8bf7\u6c42 cancel \uff0c\u95ee\u9898\u5c31\u5b8c\u7f8e\u89e3\u51b3\u4e86\u3002<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/Last-Order\/Minyami\/commit\/483628241e0ba45269e68619e0aa17f3db05cc56\">https:\/\/github.com\/Last-Order\/Minyami\/commit\/483628241e0ba45269e68619e0aa17f3db05cc56<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"twentyseventeen-featured-image":false,"twentyseventeen-thumbnail-avatar":false},"uagb_author_info":{"display_name":"Sora","author_link":"https:\/\/sora.sound.moe\/?author=1"},"uagb_comment_info":0,"uagb_excerpt":null,"_links":{"self":[{"href":"https:\/\/sora.sound.moe\/index.php?rest_route=\/wp\/v2\/posts\/789"}],"collection":[{"href":"https:\/\/sora.sound.moe\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sora.sound.moe\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sora.sound.moe\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sora.sound.moe\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=789"}],"version-history":[{"count":0,"href":"https:\/\/sora.sound.moe\/index.php?rest_route=\/wp\/v2\/posts\/789\/revisions"}],"wp:attachment":[{"href":"https:\/\/sora.sound.moe\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=789"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sora.sound.moe\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=789"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sora.sound.moe\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=789"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}