{"id":6691,"date":"2022-07-05T16:57:53","date_gmt":"2022-07-05T08:57:53","guid":{"rendered":"http:\/\/xinyiworld.top\/wordpress_it\/?p=6691"},"modified":"2026-03-04T10:45:31","modified_gmt":"2026-03-04T02:45:31","slug":"%e5%8d%8f%e7%a8%8b%e5%85%a5%e9%97%a8","status":"publish","type":"post","link":"http:\/\/xinyiworld.top\/wordpress_it\/?p=6691","title":{"rendered":"\u534f\u7a0b\u5165\u95e8"},"content":{"rendered":"<p><a href=\"https:\/\/www.bbsmax.com\/A\/kmzLNEBA5G\/\">https:\/\/www.bbsmax.com\/A\/kmzLNEBA5G\/<\/a><\/p>\n<p><a href=\"https:\/\/blog.51cto.com\/u_15548643\/5153793\">https:\/\/blog.51cto.com\/u_15548643\/5153793<\/a>\uff08\u7ed3\u5408\u5b9e\u4f8b\u4ee3\u7801\u66f4\u6613\u61c2\uff0c\u6709\u4e00\u5904\u6ce8\u91ca\u6709\u95ee\u9898\u3002\uff09<\/p>\n<p><a href=\"https:\/\/zhuanlan.zhihu.com\/p\/427092689\">https:\/\/zhuanlan.zhihu.com\/p\/427092689<\/a>\uff08\u77e5\u4e4e\uff09<\/p>\n<p><a href=\"https:\/\/www.jianshu.com\/p\/e4e7ae9473de\">https:\/\/www.jianshu.com\/p\/e4e7ae9473de<\/a>\uff08\u539f\u7406\u6027\u8bb2\u89e3\uff09<\/p>\n<p><a href=\"https:\/\/developer.android.google.cn\/kotlin\/coroutines?hl=zh-cn\">https:\/\/developer.android.google.cn\/kotlin\/coroutines?hl=zh-cn<\/a> \uff08\u5b98\u7f51\u6559\u7a0b\uff09<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_16 counter-hierarchy counter-decimal ez-toc-grey\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\">\u76ee\u5f55<\/p>\n<span class=\"ez-toc-title-toggle\"><a class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" style=\"display: none;\"><i class=\"ez-toc-glyphicon ez-toc-icon-toggle\"><\/i><\/a><\/span><\/div>\n<nav><ul class=\"ez-toc-list ez-toc-list-level-1\"><li class=\"ez-toc-page-1 ez-toc-heading-level-1\"><a class=\"ez-toc-link ez-toc-heading-1\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=6691\/#%E4%B8%80%E3%80%81%E5%8D%8F%E7%A8%8B%E7%9A%84%E6%84%8F%E4%B9%89\" title=\"\u4e00\u3001\u534f\u7a0b\u7684\u610f\u4e49\">\u4e00\u3001\u534f\u7a0b\u7684\u610f\u4e49<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-1\"><a class=\"ez-toc-link ez-toc-heading-2\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=6691\/#%E4%BA%8C%E3%80%81%E9%87%8D%E8%A6%81%E6%A6%82%E5%BF%B5\" title=\"\u4e8c\u3001\u91cd\u8981\u6982\u5ff5\">\u4e8c\u3001\u91cd\u8981\u6982\u5ff5<\/a><ul class=\"ez-toc-list-level-3\"><li class=\"ez-toc-heading-level-3\"><ul class=\"ez-toc-list-level-3\"><li class=\"ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-3\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=6691\/#%E4%BE%9D%E8%B5%96%E5%8C%85\" title=\"\u4f9d\u8d56\u5305\">\u4f9d\u8d56\u5305<\/a><\/li><\/ul><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-1\"><a class=\"ez-toc-link ez-toc-heading-4\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=6691\/#%E4%B8%89%E3%80%81%E7%9F%A5%E8%AF%86%E7%82%B9%E6%A6%82%E8%A7%88\" title=\"\u4e09\u3001\u77e5\u8bc6\u70b9\u6982\u89c8\">\u4e09\u3001\u77e5\u8bc6\u70b9\u6982\u89c8<\/a><ul class=\"ez-toc-list-level-4\"><li class=\"ez-toc-heading-level-4\"><ul class=\"ez-toc-list-level-4\"><li class=\"ez-toc-heading-level-4\"><ul class=\"ez-toc-list-level-4\"><li class=\"ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-5\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=6691\/#1_%E5%8D%8F%E7%A8%8B%E6%9E%84%E5%BB%BA%E5%99%A8_Coroutine_Builders\" title=\"1. \u534f\u7a0b\u6784\u5efa\u5668 (Coroutine Builders)\">1. \u534f\u7a0b\u6784\u5efa\u5668 (Coroutine Builders)<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-6\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=6691\/#2_%E6%8C%82%E8%B5%B7%E5%87%BD%E6%95%B0_Suspend_Functions\" title=\"2. \u6302\u8d77\u51fd\u6570 (Suspend Functions)\">2. \u6302\u8d77\u51fd\u6570 (Suspend Functions)<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-7\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=6691\/#3_%E5%8D%8F%E7%A8%8B%E4%B8%8A%E4%B8%8B%E6%96%87_CoroutineContext\" title=\"3. \u534f\u7a0b\u4e0a\u4e0b\u6587 (CoroutineContext)\">3. \u534f\u7a0b\u4e0a\u4e0b\u6587 (CoroutineContext)<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-8\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=6691\/#4_%E5%8D%8F%E7%A8%8B%E4%BD%9C%E7%94%A8%E5%9F%9F_CoroutineScope\" title=\"4. \u534f\u7a0b\u4f5c\u7528\u57df (CoroutineScope)\">4. \u534f\u7a0b\u4f5c\u7528\u57df (CoroutineScope)<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-9\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=6691\/#5_%E5%90%AF%E5%8A%A8%E6%A8%A1%E5%BC%8F_CoroutineStart\" title=\"5. \u542f\u52a8\u6a21\u5f0f (CoroutineStart)\">5. \u542f\u52a8\u6a21\u5f0f (CoroutineStart)<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-10\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=6691\/#6_%E7%BB%93%E6%9E%84%E5%8C%96%E5%B9%B6%E5%8F%91_Structured_Concurrency\" title=\"6. \u7ed3\u6784\u5316\u5e76\u53d1 (Structured Concurrency)\">6. \u7ed3\u6784\u5316\u5e76\u53d1 (Structured Concurrency)<\/a><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-11\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=6691\/#%F0%9F%92%A1_%E5%8D%8F%E7%A8%8B%E8%A7%A3%E5%86%B3%E7%9A%84%E9%97%AE%E9%A2%98\" title=\"\ud83d\udca1 \u534f\u7a0b\u89e3\u51b3\u7684\u95ee\u9898\">\ud83d\udca1 \u534f\u7a0b\u89e3\u51b3\u7684\u95ee\u9898<\/a><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"%E4%B8%80%E3%80%81%E5%8D%8F%E7%A8%8B%E7%9A%84%E6%84%8F%E4%B9%89\"><\/span>\u4e00\u3001\u534f\u7a0b\u7684\u610f\u4e49<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<ul>\n<li>\u7528\u540c\u6b65\u7684\u65b9\u5f0f\u5199\u51fa\u5f02\u6b65\u7684\u4ee3\u7801\uff0c\u7ef4\u6301\u4ee3\u7801\u7ed3\u6784\u7684\u6e05\u6670\uff0c\u907f\u514d\u56de\u8c03\u5730\u72f1\u3002<\/li>\n<\/ul>\n<h1><span class=\"ez-toc-section\" id=\"%E4%BA%8C%E3%80%81%E9%87%8D%E8%A6%81%E6%A6%82%E5%BF%B5\"><\/span>\u4e8c\u3001\u91cd\u8981\u6982\u5ff5<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<ul>\n<li>suspend \u51fd\u6570 \uff08\u6302\u8d77\u51fd\u6570\uff09<br \/>\nsuspend \u51fd\u6570\u53ea\u80fd\u5728\u534f\u7a0b\u91cc\u6216\u8005\u53e6\u4e00\u4e2a suspend \u51fd\u6570\u91cc\u88ab\u8c03\u7528\uff0c\u8fd8\u662f\u4e3a\u4e86\u8981\u8ba9\u534f\u7a0b\u80fd\u591f\u5728 suspend \u51fd\u6570\u5207\u6362\u7ebf\u7a0b\u4e4b\u540e\u518d\u5207\u56de\u6765\u3002<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"%E4%BE%9D%E8%B5%96%E5%8C%85\"><\/span>\u4f9d\u8d56\u5305<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre><code class=\"language-groovy\">implementation &#039;org.jetbrains.kotlinx:kotlinx-coroutines-core:x.x.x&#039;\nimplementation &quot;org.jetbrains.kotlinx:kotlinx-coroutines-android:x.x.x&quot;<\/code><\/pre>\n<h1><span class=\"ez-toc-section\" id=\"%E4%B8%89%E3%80%81%E7%9F%A5%E8%AF%86%E7%82%B9%E6%A6%82%E8%A7%88\"><\/span>\u4e09\u3001\u77e5\u8bc6\u70b9\u6982\u89c8<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<h4><span class=\"ez-toc-section\" id=\"1_%E5%8D%8F%E7%A8%8B%E6%9E%84%E5%BB%BA%E5%99%A8_Coroutine_Builders\"><\/span>1. \u534f\u7a0b\u6784\u5efa\u5668 (Coroutine Builders)<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<ul>\n<li><strong><code>launch<\/code><\/strong>\uff1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u534f\u7a0b\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a<strong><code>Job<\/code><\/strong>\uff0c\u4ee3\u8868\u534f\u7a0b\u672c\u8eab\u3002\u5b83<strong>\u4e0d\u8fd4\u56de\u4efb\u4f55\u7ed3\u679c<\/strong>\uff0c\u9002\u7528\u4e8e\u201c\u53d1\u540e\u5373\u5fd8\u201d\u7684\u573a\u666f\u3002<\/li>\n<li><strong><code>async<\/code><\/strong>\uff1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u534f\u7a0b\uff0c\u8fd4\u56de\u4e00\u4e2a<strong><code>Deferred&lt;T&gt;<\/code><\/strong>\u5bf9\u8c61\uff08<code>Job<\/code>\u7684\u5b50\u63a5\u53e3\uff09\u3002\u901a\u8fc7\u5728\u5176\u4e0a\u8c03\u7528<code>.await()<\/code>\uff0c\u53ef\u4ee5<strong>\u6302\u8d77\u5e76\u83b7\u53d6\u6700\u7ec8\u8fd4\u56de\u7684\u7ed3\u679c<\/strong>\u3002\u5e38\u7528\u4e8e\u5e76\u53d1\u6267\u884c\u4efb\u52a1\u3002<\/li>\n<li><strong><code>runBlocking<\/code><\/strong>\uff1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u534f\u7a0b\u5e76<strong>\u963b\u585e\u5f53\u524d\u7ebf\u7a0b<\/strong>\uff0c\u76f4\u5230\u5176\u5185\u90e8\u6240\u6709\u903b\u8f91\u6267\u884c\u5b8c\u6bd5\u3002\u5b83\u4e3b\u8981\u7528\u4e8e<strong>\u6865\u63a5\u666e\u901a\u963b\u585e\u4ee3\u7801\u548c\u6302\u8d77\u98ce\u683c\u4ee3\u7801<\/strong>\uff08\u5982\u5728<code>main<\/code>\u51fd\u6570\u6216\u6d4b\u8bd5\u4e2d\uff09\uff0c\u65e5\u5e38Android\u5f00\u53d1\u4e2d\u5e94\u907f\u514d\u4f7f\u7528\u3002<\/li>\n<\/ul>\n<h4><span class=\"ez-toc-section\" id=\"2_%E6%8C%82%E8%B5%B7%E5%87%BD%E6%95%B0_Suspend_Functions\"><\/span>2. \u6302\u8d77\u51fd\u6570 (Suspend Functions)<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<ul>\n<li>\u4f7f\u7528<code>suspend<\/code>\u5173\u952e\u5b57\u4fee\u9970\u7684\u51fd\u6570\u3002<\/li>\n<li><strong>\u6838\u5fc3\u7279\u6027<\/strong>\uff1a\u53ef\u4ee5\u5728\u51fd\u6570\u5185\u90e8<strong>\u6302\u8d77<\/strong>\u5f53\u524d\u534f\u7a0b\u7684\u6267\u884c\uff0c\u800c<strong>\u4e0d\u4f1a\u963b\u585e<\/strong>\u5176\u6240\u5728\u7684\u7ebf\u7a0b\u3002\u5f53\u6302\u8d77\u64cd\u4f5c\uff08\u5982<code>delay<\/code>\u3001\u7f51\u7edc\u8bf7\u6c42\uff09\u5b8c\u6210\u540e\uff0c\u534f\u7a0b\u4f1a\u5728\u540e\u7eed\u67d0\u4e2a\u65f6\u95f4\u70b9<strong>\u6062\u590d<\/strong>\u6267\u884c\u3002<\/li>\n<li><strong>\u539f\u7406<\/strong>\uff1a\u7f16\u8bd1\u65f6\u4f1a\u88ab\u6dfb\u52a0\u4e00\u4e2a<code>Continuation<\/code>\u53c2\u6570\uff0c\u5176\u51fd\u6570\u4f53\u88ab\u7f16\u8bd1\u6210\u4e00\u4e2a<strong>\u72b6\u6001\u673a<\/strong>\uff0c\u6bcf\u4e2a\u6302\u8d77\u70b9\u5bf9\u5e94\u4e00\u4e2a\u72b6\u6001\uff0c\u4ece\u800c\u7528\u540c\u6b65\u7684\u65b9\u5f0f\u5199\u51fa\u5f02\u6b65\u7684\u4ee3\u7801\u3002<\/li>\n<\/ul>\n<h4><span class=\"ez-toc-section\" id=\"3_%E5%8D%8F%E7%A8%8B%E4%B8%8A%E4%B8%8B%E6%96%87_CoroutineContext\"><\/span>3. \u534f\u7a0b\u4e0a\u4e0b\u6587 (CoroutineContext)<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>\u5b83\u662f\u534f\u7a0b\u8fd0\u884c\u73af\u5883\u7684<strong>\u6301\u4e45\u5316\u96c6\u5408<\/strong>\uff0c\u4e3b\u8981\u5305\u542b\u4ee5\u4e0b\u51e0\u4e2a\u5173\u952e\u5143\u7d20\uff1a<\/p>\n<ul>\n<li><strong><code>Job<\/code><\/strong>\uff1a<strong>\u63a7\u5236\u534f\u7a0b\u7684\u751f\u547d\u5468\u671f<\/strong>\u3002\u53ef\u4ee5\u7528\u4e8e\u5224\u65ad\u534f\u7a0b\u662f\u5426\u6d3b\u8dc3\u3001\u53d6\u6d88\u534f\u7a0b\u3001\u7b49\u5f85\u5b50\u534f\u7a0b\u5b8c\u6210\u7b49\u3002\u6bcf\u4e2a\u534f\u7a0b\u90fd\u6709\u81ea\u5df1\u7684<code>Job<\/code>\u3002<\/li>\n<li><strong><code>CoroutineDispatcher<\/code> (\u8c03\u5ea6\u5668)<\/strong>\uff1a<strong>\u51b3\u5b9a\u534f\u7a0b\u5728\u54ea\u4e2a\u7ebf\u7a0b\u6216\u7ebf\u7a0b\u6c60\u4e0a\u6267\u884c<\/strong>\u3002\u4e3b\u8981\u7c7b\u578b\u6709\uff1a\n<ul>\n<li><code>Dispatchers.Main<\/code>\uff1a\u4e3b\u7ebf\u7a0b\uff0c\u7528\u4e8eUI\u64cd\u4f5c\u3002<\/li>\n<li><code>Dispatchers.IO<\/code>\uff1a\u9002\u5408\u6267\u884c\u78c1\u76d8\u6216\u7f51\u7edcI\/O\u64cd\u4f5c\uff08\u5982\u6587\u4ef6\u8bfb\u5199\u3001\u7f51\u7edc\u8bf7\u6c42\uff09\u3002<\/li>\n<li><code>Dispatchers.Default<\/code>\uff1a\u9002\u5408\u6267\u884cCPU\u5bc6\u96c6\u578b\u4efb\u52a1\uff08\u5982\u5217\u8868\u6392\u5e8f\u3001JSON\u89e3\u6790\uff09\u3002<\/li>\n<li><code>Dispatchers.Unconfined<\/code>\uff1a\u4e0d\u9650\u5b9a\u7ebf\u7a0b\uff0c\u5728\u7b2c\u4e00\u4e2a\u6302\u8d77\u70b9\u4e4b\u524d\u8fd0\u884c\u5728\u5f53\u524d\u7ebf\u7a0b\uff0c\u4e4b\u540e\u7531\u8c03\u7528<code>resume<\/code>\u7684\u7ebf\u7a0b\u51b3\u5b9a\uff08\u6781\u5c11\u4f7f\u7528\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong><code>CoroutineName<\/code><\/strong>\uff1a\u4e3a\u534f\u7a0b\u547d\u540d\uff0c\u65b9\u4fbf\u8c03\u8bd5\u3002<\/li>\n<li><strong><code>CoroutineExceptionHandler<\/code><\/strong>\uff1a\u7528\u4e8e\u5904\u7406\u534f\u7a0b\u4e2d\u672a\u6355\u83b7\u7684\u5f02\u5e38\u3002<\/li>\n<\/ul>\n<h4><span class=\"ez-toc-section\" id=\"4_%E5%8D%8F%E7%A8%8B%E4%BD%9C%E7%94%A8%E5%9F%9F_CoroutineScope\"><\/span>4. \u534f\u7a0b\u4f5c\u7528\u57df (CoroutineScope)<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<ul>\n<li>\u5b9a\u4e49\u4e86\u65b0\u542f\u52a8\u7684\u534f\u7a0b\u7684<strong>\u751f\u547d\u5468\u671f\u8fb9\u754c<\/strong>\u3002\u5b83\u6301\u6709\u81ea\u5df1\u7684<code>CoroutineContext<\/code>\u3002<\/li>\n<li><strong>\u91cd\u8981\u6027<\/strong>\uff1a\u901a\u8fc7\u4f5c\u7528\u57df\u53ef\u4ee5<strong>\u8ddf\u8e2a\u548c\u7ba1\u7406\u5176\u5185\u90e8\u6240\u6709\u534f\u7a0b<\/strong>\u3002\u5f53\u4f5c\u7528\u57df\u88ab\u53d6\u6d88\u65f6\uff0c\u5176\u5185\u90e8\u6240\u6709\u6b63\u5728\u8fd0\u884c\u7684\u534f\u7a0b\u90fd\u4f1a\u88ab\u81ea\u52a8\u53d6\u6d88\uff0c\u6709\u6548<strong>\u9632\u6b62\u534f\u7a0b\u6cc4\u6f0f<\/strong>\u3002<\/li>\n<li><strong>\u5e38\u7528\u4f5c\u7528\u57df<\/strong>\uff1a\n<ul>\n<li><code>GlobalScope<\/code>\uff1a\u5168\u5c40\u4f5c\u7528\u57df\uff0c\u751f\u547d\u5468\u671f\u4e0e\u6574\u4e2a\u5e94\u7528\u4e00\u81f4\uff0c\u4e00\u822c\u4e0d\u63a8\u8350\u4f7f\u7528\u3002<\/li>\n<li><code>lifecycleScope<\/code> (\u5728<code>androidx.lifecycle:lifecycle-runtime-ktx<\/code>\u4e2d)\uff1a\u6bcf\u4e2a<code>LifecycleOwner<\/code>\uff08\u5982<code>Activity<\/code>\/<code>Fragment<\/code>\uff09\u90fd\u6709\u3002\u5f53<code>Lifecycle<\/code>\u9500\u6bc1\u65f6\uff0c\u8be5\u4f5c\u7528\u57df\u5185\u7684\u534f\u7a0b\u81ea\u52a8\u53d6\u6d88\u3002<\/li>\n<li><code>viewModelScope<\/code> (\u5728<code>androidx.lifecycle:lifecycle-viewmodel-ktx<\/code>\u4e2d)\uff1a\u6bcf\u4e2a<code>ViewModel<\/code>\u90fd\u6709\u3002\u5f53<code>ViewModel<\/code>\u88ab\u6e05\u9664\u65f6\uff0c\u5176\u5185\u90e8\u7684\u534f\u7a0b\u81ea\u52a8\u53d6\u6d88\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4><span class=\"ez-toc-section\" id=\"5_%E5%90%AF%E5%8A%A8%E6%A8%A1%E5%BC%8F_CoroutineStart\"><\/span>5. \u542f\u52a8\u6a21\u5f0f (CoroutineStart)<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<ul>\n<li><strong><code>DEFAULT<\/code><\/strong>\uff1a<strong>\u7acb\u5373<\/strong>\u8c03\u5ea6\u6267\u884c\u534f\u7a0b\uff0c\u968f\u65f6\u53ef\u4ee5\u53d6\u6d88\u3002<\/li>\n<li><strong><code>LAZY<\/code><\/strong>\uff1a<strong>\u61d2\u52a0\u8f7d\u6a21\u5f0f<\/strong>\uff0c\u53ea\u6709\u5728\u9700\u8981\u65f6\uff08\u5982\u8c03\u7528<code>Job.start()<\/code>\u3001<code>Job.join()<\/code>\u6216<code>Deferred.await()<\/code>\uff09\u624d\u4f1a\u5f00\u59cb\u6267\u884c\u3002<\/li>\n<li><code>ATOMIC<\/code>\uff1a\u7c7b\u4f3c\u4e8e<code>DEFAULT<\/code>\uff0c\u4f46\u5728\u5f00\u59cb\u8fd0\u884c\u524d<strong>\u4e0d\u80fd\u88ab\u53d6\u6d88<\/strong>\u3002<\/li>\n<li><code>UNDISPATCHED<\/code>\uff1a\u534f\u7a0b\u521b\u5efa\u540e\uff0c\u7acb\u5373\u5728\u5f53\u524d\u7ebf\u7a0b\u6267\u884c\uff0c\u76f4\u5230\u9047\u5230\u7b2c\u4e00\u4e2a\u6302\u8d77\u70b9\u3002<\/li>\n<\/ul>\n<h4><span class=\"ez-toc-section\" id=\"6_%E7%BB%93%E6%9E%84%E5%8C%96%E5%B9%B6%E5%8F%91_Structured_Concurrency\"><\/span>6. \u7ed3\u6784\u5316\u5e76\u53d1 (Structured Concurrency)<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>\u8fd9\u662fKotlin\u534f\u7a0b\u7684\u6838\u5fc3\u8bbe\u8ba1\u7406\u5ff5\uff0c\u5176\u539f\u5219\u662f\uff1a<\/p>\n<ul>\n<li><strong>\u7236\u5b50\u5c42\u7ea7<\/strong>\uff1a\u534f\u7a0b\u5fc5\u987b\u5728\u67d0\u4e2a<code>CoroutineScope<\/code>\u4e2d\u542f\u52a8\uff0c\u5f62\u6210\u4e00\u4e2a\u7236\u5b50\u5173\u7cfb\u3002<\/li>\n<li><strong>\u751f\u547d\u5468\u671f\u7ee7\u627f<\/strong>\uff1a\u7236\u534f\u7a0b\u88ab\u53d6\u6d88\uff0c\u6240\u6709\u5b50\u534f\u7a0b\u81ea\u52a8\u53d6\u6d88\u3002\u7236\u534f\u7a0b\u4f1a\u7b49\u5f85\u6240\u6709\u5b50\u534f\u7a0b\u5b8c\u6210\u540e\u518d\u5b8c\u6210\u3002<\/li>\n<li><strong>\u5f02\u5e38\u4f20\u64ad<\/strong>\uff1a\u5b50\u534f\u7a0b\u7684\u672a\u6355\u83b7\u5f02\u5e38\u4f1a\u9ed8\u8ba4\u5411\u4e0a\u4f20\u64ad\u7ed9\u7236\u534f\u7a0b\uff0c\u5bfc\u81f4\u7236\u534f\u7a0b\u4e5f\u5931\u8d25\u3002<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"%F0%9F%92%A1_%E5%8D%8F%E7%A8%8B%E8%A7%A3%E5%86%B3%E7%9A%84%E9%97%AE%E9%A2%98\"><\/span>\ud83d\udca1 \u534f\u7a0b\u89e3\u51b3\u7684\u95ee\u9898<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u6b63\u5982\u6587\u7ae0\u5f00\u5934\u6240\u8ff0\uff0c\u534f\u7a0b\u4f18\u96c5\u5730\u89e3\u51b3\u4e86\u4e24\u4e2a\u6838\u5fc3\u95ee\u9898\uff1a<\/p>\n<ol>\n<li><strong>\u5904\u7406\u8017\u65f6\u4efb\u52a1<\/strong>\uff1a\u901a\u8fc7<strong>\u975e\u963b\u585e\u6302\u8d77<\/strong>\uff0c\u5c06\u8017\u65f6\u64cd\u4f5c\u4ece\u4e3b\u7ebf\u7a0b\u79fb\u5f00\uff0c\u907f\u514dANR\u3002<\/li>\n<li><strong>\u4fdd\u8bc1\u4e3b\u7ebf\u7a0b\u5b89\u5168<\/strong>\uff1a\u901a\u8fc7\u8c03\u5ea6\u5668\uff08<code>Dispatchers<\/code>\uff09\u65b9\u4fbf\u5730\u5728\u4e0d\u540c\u7ebf\u7a0b\u95f4\u5207\u6362\uff0c\u5e76\u5229\u7528\u6302\u8d77\u51fd\u6570\u4fdd\u8bc1\u4efb\u4f55<code>suspend<\/code>\u51fd\u6570\u90fd\u53ef\u4ee5\u5b89\u5168\u5730\u4ece\u4e3b\u7ebf\u7a0b\u8c03\u7528\u3002<\/li>\n<\/ol>\n<button class=\"simplefavorite-button\" data-postid=\"6691\" data-siteid=\"1\" data-groupid=\"1\" data-favoritecount=\"0\" style=\"\">\u6536\u85cf <i class=\"sf-icon-star-empty\"><\/i><\/button>","protected":false},"excerpt":{"rendered":"<p>https:\/\/www.bbsmax.com\/A\/kmzLNEBA5G\/ https:\/\/blog. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[452],"tags":[],"_links":{"self":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/6691"}],"collection":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6691"}],"version-history":[{"count":18,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/6691\/revisions"}],"predecessor-version":[{"id":16212,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/6691\/revisions\/16212"}],"wp:attachment":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6691"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6691"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6691"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}