{"id":409,"date":"2022-11-24T16:11:45","date_gmt":"2022-11-24T08:11:45","guid":{"rendered":"https:\/\/iichen.cn\/?p=409"},"modified":"2022-11-24T16:11:45","modified_gmt":"2022-11-24T08:11:45","slug":"kotlin-%e5%8d%8f%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/iichen.cn\/?p=409","title":{"rendered":"kotlin-\u534f\u7a0b"},"content":{"rendered":"<h5>1. \u57fa\u672c\u8ba4\u8bc6<\/h5>\n<blockquote><p>\n  Kotlin \u7684\u7f16\u8bd1\u5668\u68c0\u6d4b\u5230 suspend \u5173\u952e\u5b57\u4fee\u9970\u7684\u51fd\u6570\u4ee5\u540e\uff0c\u4f1a\u81ea\u52a8\u5c06\u6302\u8d77\u51fd\u6570\u8f6c\u6362\u6210\u5e26\u6709 CallBack \u7684\u51fd\u6570\n<\/p><\/blockquote>\n<pre><code class=\"language-java line-numbers\">suspend fun getUserInfo(): String {\n    withContext(Dispatchers.IO) {\n        delay(1000L)\n    }\n    return \"BoyCoder\"\n}\n\n\n\/\/                              Continuation \u7b49\u4ef7\u4e8e CallBack\n\/\/                                         \u2193         \npublic static final Object getUserInfo(Continuation $completion) {\n  ...\n  return \"BoyCoder\";\n}\n<\/code><\/pre>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/p3-juejin.byteimg.com\/tos-cn-i-k3u1fbpfcp\/60453cfebece44779b6581aefef14284~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/p3-juejin.byteimg.com\/tos-cn-i-k3u1fbpfcp\/60453cfebece44779b6581aefef14284~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image'><img class=\"lazyload lazyload-style-11\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/p3-juejin.byteimg.com\/tos-cn-i-k3u1fbpfcp\/60453cfebece44779b6581aefef14284~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/a><\/p>\n<blockquote>\n<\/blockquote>\n<p style=\"color:green\">\u91cd\u70b9\u662f\u8fd9\u4e2a\u56fe\u7247,\u540e\u9762\u5206\u6790\u6302\u8d77\u51fd\u6570\u5185\u591a\u4e2a\u6302\u8d77\u51fd\u6570\uff0c\u7406\u89e3\u5b9e\u73b0\u72b6\u6001\u673a\u5207\u6362\u76f8\u5173\u56de\u8c03<\/p>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/p6-juejin.byteimg.com\/tos-cn-i-k3u1fbpfcp\/05a867ae47974a55a71c62a324f48538~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/p6-juejin.byteimg.com\/tos-cn-i-k3u1fbpfcp\/05a867ae47974a55a71c62a324f48538~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image'><img class=\"lazyload lazyload-style-11\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/p6-juejin.byteimg.com\/tos-cn-i-k3u1fbpfcp\/05a867ae47974a55a71c62a324f48538~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/a><\/p>\n<blockquote><p>\n  <strong>\u524d\u540esuspend ()->String \u53d8\u6210\u4e86 (Continuation)-> Any?<\/strong><br \/>\n   \u7531\u4e8e suspend \u4fee\u9970\u7684\u51fd\u6570\uff0c\u65e2\u53ef\u80fd\u8fd4\u56de CoroutineSingletons.COROUTINE_SUSPENDED\uff0c\u4e5f\u53ef\u80fd\u8fd4\u56de\u5b9e\u9645\u7ed3\u679c&#8221;no suspend&#8221;\uff0c\u751a\u81f3\u53ef\u80fd\u8fd4\u56de null\uff0c\u4e3a\u4e86\u9002\u914d\u6240\u6709\u7684\u53ef\u80fd\u6027\uff0cCPS \u8f6c\u6362\u540e\u7684\u51fd\u6570\u8fd4\u56de\u503c\u7c7b\u578b\u5c31\u53ea\u80fd\u662f Any?\u4e86\u3002\n<\/p><\/blockquote>\n<h5>2. \u53cd\u7f16\u8bd1\u540e\u5206\u6790<\/h5>\n<pre><code class=\"language-java line-numbers\">suspend fun testCoroutine() {\n    log(\"start\")\n    val user = getUserInfo()\n    log(user)\n    val friendList = getFriendList(user)\n    log(friendList)\n    val feedList = getFeedList(friendList)\n    log(feedList)\n}\n\n\/\/ \u6ca1\u4e86 suspend\uff0c\u591a\u4e86 completion\nfun testCoroutine(completion: Continuation&lt;Any?&gt;): Any? {}\n\n\/\/ \u6ce8\u610f\u4e0a\u56fe \u8868\u793a completion\u5bf9\u5e94\u7684\u662f\u4ec0\u4e48\uff0c\u5b9e\u73b0 invoke\u56de\u8c03 \u4ece\u800c\u6267\u884c\u540e\u7eed\u7684 \u6302\u8d77\u51fd\u6570\nfun getUserInfo(completion: Continuation&lt;Any?&gt;): Any?{}\nfun getFriendList(user: String, completion: Continuation&lt;Any?&gt;): Any?{}\nfun getFeedList(friendList: String, completion: Continuation&lt;Any?&gt;): Any?{}\n<\/code><\/pre>\n<blockquote><p>\n  \u5728 testCoroutine \u51fd\u6570\u91cc\uff0c\u4f1a\u591a\u51fa\u4e00\u4e2a ContinuationImpl \u7684\u5b50\u7c7b\uff0c\u5b83\u7684\u662f\u6574\u4e2a\u534f\u7a0b\u6302\u8d77\u51fd\u6570\u7684\u6838\u5fc3\n<\/p><\/blockquote>\n<pre><code class=\"language-java line-numbers\">fun testCoroutine(completion: Continuation&lt;Any?&gt;): Any? {\n    \/\/ \u521d\u59cb\u5316\u5224\u65ad\u662f\u5426\u6709 \u2018\u56de\u8c03\u2019\u5b9e\u4f8b\uff0c\u9632\u6b62\u91cd\u590d\u521b\u5efa\n    val continuation = if (completion is TestContinuation) {\n        completion\n    } else {\n        \/\/                \u4f5c\u4e3a\u53c2\u6570\n        \/\/                   \u2193\n        TestContinuation(completion)\n    }\n\n\n    \/\/ completion\u53c2\u6570  \u5bf9\u5e94?\u8bf4\u7684\u90a3\u4e2a\u56fe\n    class TestContinuation(completion: Continuation&lt;Any?&gt;?) : ContinuationImpl(completion) {\n        \/\/ \u8868\u793a\u534f\u7a0b\u72b6\u6001\u673a\u5f53\u524d\u7684\u72b6\u6001\n        var label: Int = 0\n        \/\/ \u534f\u7a0b\u8fd4\u56de\u7ed3\u679c\n        var result: Any? = null\n\n        \/\/ \u7528\u4e8e\u4fdd\u5b58\u4e4b\u524d\u534f\u7a0b\u7684\u8ba1\u7b97\u7ed3\u679c\n        var mUser: Any? = null\n        var mFriendList: Any? = null\n\n        \/\/ invokeSuspend \u662f\u534f\u7a0b\u7684\u5173\u952e\n        \/\/ \u5b83\u6700\u7ec8\u4f1a\u8c03\u7528 testCoroutine(this) \u5f00\u542f\u534f\u7a0b\u72b6\u6001\u673a\n        \/\/ \u72b6\u6001\u673a\u76f8\u5173\u4ee3\u7801\u5c31\u662f\u540e\u9762\u7684 when \u8bed\u53e5\n        \/\/ \u534f\u7a0b\u7684\u672c\u8d28\uff0c\u53ef\u4ee5\u8bf4\u5c31\u662f CPS + \u72b6\u6001\u673a\n        override fun invokeSuspend(_result: Result&lt;Any?&gt;): Any? {\n            result = _result\n            label = label or Int.Companion.MIN_VALUE\n            return testCoroutine(this)\n        }\n    }\n\n    \/\/ \u4e09\u4e2a\u53d8\u91cf\uff0c\u5bf9\u5e94\u539f\u51fd\u6570\u7684\u4e09\u4e2a\u53d8\u91cf\n    lateinit var user: String\n    lateinit var friendList: String\n    lateinit var feedList: String\n\n    \/\/ result \u63a5\u6536\u534f\u7a0b\u7684\u8fd0\u884c\u7ed3\u679c\n    var result = continuation.result\n\n    \/\/ suspendReturn \u63a5\u6536\u6302\u8d77\u51fd\u6570\u7684\u8fd4\u56de\u503c\n    var suspendReturn: Any? = null\n\n    \/\/ CoroutineSingletons \u662f\u4e2a\u679a\u4e3e\u7c7b\n    \/\/ COROUTINE_SUSPENDED \u4ee3\u8868\u5f53\u524d\u51fd\u6570\u88ab\u6302\u8d77\u4e86\n    val sFlag = CoroutineSingletons.COROUTINE_SUSPENDED\n\n    when (continuation.label) {\n        0 -&gt; {\n            \/\/ \u68c0\u6d4b\u5f02\u5e38\n            throwOnFailure(result)\n\n            log(\"start\")\n            \/\/ \u5c06 label \u7f6e\u4e3a 1\uff0c\u51c6\u5907\u8fdb\u5165\u4e0b\u4e00\u6b21\u72b6\u6001\n            continuation.label = 1\n\n            \/\/ \u6267\u884c getUserInfo\n            suspendReturn = getUserInfo(continuation)\n\n            \/\/ \u5224\u65ad\u662f\u5426\u6302\u8d77\n            if (suspendReturn == sFlag) {\n                return suspendReturn\n            } else {\n                result = suspendReturn\n                \/\/go to next state  \u4f1a\u4f7f\u7528\u5230label\u76f8\u5173\u7684 goto\u8bed\u6cd5\uff0c\u4ec5\u4ec5\u4f7f\u7528suspend\u8fdb\u884c\u4fee\u9970\uff0c\u5e76\u6ca1\u6709\u76f8\u5e94\u7684\u534f\u7a0b\u57df-\u201c\u4f2a\u6302\u8d77\u51fd\u6570\u201d \u4f1a\u8d70\u5230\u8fd9\u91cc\n            }\n        }\n\n        1 -&gt; {\n            throwOnFailure(result)\n\n            \/\/ \u83b7\u53d6 user \u503c\n            user = result as String\n            log(user)\n            \/\/ \u5c06\u534f\u7a0b\u7ed3\u679c\u5b58\u5230 continuation \u91cc\n            continuation.mUser = user\n            \/\/ \u51c6\u5907\u8fdb\u5165\u4e0b\u4e00\u4e2a\u72b6\u6001\n            continuation.label = 2\n\n            \/\/ \u6267\u884c getFriendList\n            suspendReturn = getFriendList(user, continuation)\n\n            \/\/ \u5224\u65ad\u662f\u5426\u6302\u8d77\n            if (suspendReturn == sFlag) {\n                return suspendReturn\n            } else {\n                result = suspendReturn\n                \/\/go to next state\n            }\n        }\n\n        2 -&gt; {\n            throwOnFailure(result)\n\n            user = continuation.mUser as String\n\n            \/\/ \u83b7\u53d6 friendList \u7684\u503c\n            friendList = result as String\n            log(friendList)\n\n            \/\/ \u5c06\u534f\u7a0b\u7ed3\u679c\u5b58\u5230 continuation \u91cc\n            continuation.mUser = user\n            continuation.mFriendList = friendList\n\n            \/\/ \u51c6\u5907\u8fdb\u5165\u4e0b\u4e00\u4e2a\u72b6\u6001\n            continuation.label = 3\n\n            \/\/ \u6267\u884c getFeedList\n            suspendReturn = getFeedList(friendList, continuation)\n\n            \/\/ \u5224\u65ad\u662f\u5426\u6302\u8d77\n            if (suspendReturn == sFlag) {\n                return suspendReturn\n            } else {\n                result = suspendReturn\n                \/\/go to next state\n            }\n        }\n\n        3 -&gt; {\n            throwOnFailure(result)\n\n            user = continuation.mUser as String\n            friendList = continuation.mFriendList as String\n            feedList = continuation.result as String\n            log(feedList)\n            loop = false\n        }\n    }\n}\n<\/code><\/pre>\n<ul>\n<li>when \u8868\u8fbe\u5f0f\u5b9e\u73b0\u4e86\u534f\u7a0b\u72b6\u6001\u673a<\/li>\n<li>continuation.label \u662f\u72b6\u6001\u6d41\u8f6c\u7684\u5173\u952e<\/li>\n<li>continuation.label \u6539\u53d8\u4e00\u6b21\uff0c\u5c31\u4ee3\u8868\u534f\u7a0b\u5207\u6362\u4e86\u4e00\u6b21<\/li>\n<li>\u6bcf\u6b21\u534f\u7a0b\u5207\u6362\u540e\uff0c\u90fd\u4f1a\u68c0\u67e5\u662f\u5426\u53d1\u751f\u5f02\u5e38<\/li>\n<li>testCoroutine \u91cc\u7684\u539f\u672c\u7684\u4ee3\u7801\uff0c\u88ab\u62c6\u5206\u5230\u72b6\u6001\u673a\u91cc\u5404\u4e2a\u72b6\u6001\u4e2d\uff0c\u5206\u5f00\u6267\u884c<\/li>\n<li>getUserInfo(continuation)\uff0cgetFriendList(user, continuation)\uff0cgetFeedList(friendList, continuation) \u4e09\u4e2a\u51fd\u6570\u8c03\u7528\u4f20\u7684\u540c\u4e00\u4e2a continuation \u5b9e\u4f8b\u3002<\/li>\n<li>\u4e00\u4e2a\u51fd\u6570\u5982\u679c\u88ab\u6302\u8d77\u4e86\uff0c\u5b83\u7684\u8fd4\u56de\u503c\u4f1a\u662f\uff1aCoroutineSingletons.COROUTINE_SUSPENDED<\/li>\n<li>\u5207\u6362\u534f\u7a0b\u4e4b\u524d\uff0c\u72b6\u6001\u673a\u4f1a\u628a\u4e4b\u524d\u7684\u7ed3\u679c\u4ee5\u6210\u5458\u53d8\u91cf\u7684\u65b9\u5f0f\u4fdd\u5b58\u5728 continuation \u4e2d\u3002<\/li>\n<\/ul>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/p9-juejin.byteimg.com\/tos-cn-i-k3u1fbpfcp\/de2b6b97c0284becbc6d329cbd66e4ab~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/p9-juejin.byteimg.com\/tos-cn-i-k3u1fbpfcp\/de2b6b97c0284becbc6d329cbd66e4ab~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image'><img class=\"lazyload lazyload-style-11\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/p9-juejin.byteimg.com\/tos-cn-i-k3u1fbpfcp\/de2b6b97c0284becbc6d329cbd66e4ab~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/a><\/p>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/p9-juejin.byteimg.com\/tos-cn-i-k3u1fbpfcp\/56ba74c4febf4140a26174eac73e1880~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/p9-juejin.byteimg.com\/tos-cn-i-k3u1fbpfcp\/56ba74c4febf4140a26174eac73e1880~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image'><img class=\"lazyload lazyload-style-11\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/p9-juejin.byteimg.com\/tos-cn-i-k3u1fbpfcp\/56ba74c4febf4140a26174eac73e1880~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/a><\/p>\n<p><strong><center style=\"color:red\">\u4ee5\u4e0b\u4ee3\u7801\u4e3a\u4f2a\u4ee3\u7801<\/center><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. \u57fa\u672c\u8ba4\u8bc6 Kotlin \u7684\u7f16\u8bd1\u5668\u68c0\u6d4b\u5230 suspend \u5173\u952e\u5b57\u4fee\u9970\u7684\u51fd\u6570\u4ee5\u540e\uff0c\u4f1a\u81ea\u52a8\u5c06\u6302\u8d77\u51fd\u6570\u8f6c\u6362\u6210\u5e26\u6709 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,8],"tags":[],"class_list":["post-409","post","type-post","status-publish","format-standard","hentry","category-android","category-8"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>kotlin-\u534f\u7a0b - IIchen<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/iichen.cn\/?p=409\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"kotlin-\u534f\u7a0b - IIchen\" \/>\n<meta property=\"og:description\" content=\"1. \u57fa\u672c\u8ba4\u8bc6 Kotlin \u7684\u7f16\u8bd1\u5668\u68c0\u6d4b\u5230 suspend \u5173\u952e\u5b57\u4fee\u9970\u7684\u51fd\u6570\u4ee5\u540e\uff0c\u4f1a\u81ea\u52a8\u5c06\u6302\u8d77\u51fd\u6570\u8f6c\u6362\u6210\u5e26\u6709 [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/iichen.cn\/?p=409\" \/>\n<meta property=\"og:site_name\" content=\"IIchen\" \/>\n<meta property=\"article:published_time\" content=\"2022-11-24T08:11:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/p3-juejin.byteimg.com\/tos-cn-i-k3u1fbpfcp\/60453cfebece44779b6581aefef14284~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image\" \/>\n<meta name=\"author\" content=\"iichen\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"iichen\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/iichen.cn\/?p=409#article\",\"isPartOf\":{\"@id\":\"https:\/\/iichen.cn\/?p=409\"},\"author\":{\"name\":\"iichen\",\"@id\":\"https:\/\/iichen.cn\/#\/schema\/person\/4a47edf85ab49841df9e8f6aee40b77c\"},\"headline\":\"kotlin-\u534f\u7a0b\",\"datePublished\":\"2022-11-24T08:11:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/iichen.cn\/?p=409\"},\"wordCount\":40,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/iichen.cn\/#\/schema\/person\/4a47edf85ab49841df9e8f6aee40b77c\"},\"image\":{\"@id\":\"https:\/\/iichen.cn\/?p=409#primaryimage\"},\"thumbnailUrl\":\"https:\/\/p3-juejin.byteimg.com\/tos-cn-i-k3u1fbpfcp\/60453cfebece44779b6581aefef14284~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image\",\"articleSection\":[\"Android\",\"\u7b14\u8bb0\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/iichen.cn\/?p=409#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/iichen.cn\/?p=409\",\"url\":\"https:\/\/iichen.cn\/?p=409\",\"name\":\"kotlin-\u534f\u7a0b - IIchen\",\"isPartOf\":{\"@id\":\"https:\/\/iichen.cn\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/iichen.cn\/?p=409#primaryimage\"},\"image\":{\"@id\":\"https:\/\/iichen.cn\/?p=409#primaryimage\"},\"thumbnailUrl\":\"https:\/\/p3-juejin.byteimg.com\/tos-cn-i-k3u1fbpfcp\/60453cfebece44779b6581aefef14284~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image\",\"datePublished\":\"2022-11-24T08:11:45+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/iichen.cn\/?p=409#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/iichen.cn\/?p=409\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/iichen.cn\/?p=409#primaryimage\",\"url\":\"https:\/\/p3-juejin.byteimg.com\/tos-cn-i-k3u1fbpfcp\/60453cfebece44779b6581aefef14284~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image\",\"contentUrl\":\"https:\/\/p3-juejin.byteimg.com\/tos-cn-i-k3u1fbpfcp\/60453cfebece44779b6581aefef14284~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/iichen.cn\/?p=409#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/iichen.cn\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"kotlin-\u534f\u7a0b\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/iichen.cn\/#website\",\"url\":\"https:\/\/iichen.cn\/\",\"name\":\"IIchen\",\"description\":\"Just do it!\",\"publisher\":{\"@id\":\"https:\/\/iichen.cn\/#\/schema\/person\/4a47edf85ab49841df9e8f6aee40b77c\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/iichen.cn\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-Hans\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/iichen.cn\/#\/schema\/person\/4a47edf85ab49841df9e8f6aee40b77c\",\"name\":\"iichen\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/iichen.cn\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/iichen.cn\/wp-content\/uploads\/2025\/01\/avatar.jpg\",\"contentUrl\":\"https:\/\/iichen.cn\/wp-content\/uploads\/2025\/01\/avatar.jpg\",\"width\":940,\"height\":940,\"caption\":\"iichen\"},\"logo\":{\"@id\":\"https:\/\/iichen.cn\/#\/schema\/person\/image\/\"},\"sameAs\":[\"https:\/\/www.iichen.cn\"],\"url\":\"https:\/\/iichen.cn\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"kotlin-\u534f\u7a0b - IIchen","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/iichen.cn\/?p=409","og_locale":"zh_CN","og_type":"article","og_title":"kotlin-\u534f\u7a0b - IIchen","og_description":"1. \u57fa\u672c\u8ba4\u8bc6 Kotlin \u7684\u7f16\u8bd1\u5668\u68c0\u6d4b\u5230 suspend \u5173\u952e\u5b57\u4fee\u9970\u7684\u51fd\u6570\u4ee5\u540e\uff0c\u4f1a\u81ea\u52a8\u5c06\u6302\u8d77\u51fd\u6570\u8f6c\u6362\u6210\u5e26\u6709 [&hellip;]","og_url":"https:\/\/iichen.cn\/?p=409","og_site_name":"IIchen","article_published_time":"2022-11-24T08:11:45+00:00","og_image":[{"url":"https:\/\/p3-juejin.byteimg.com\/tos-cn-i-k3u1fbpfcp\/60453cfebece44779b6581aefef14284~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image","type":"","width":"","height":""}],"author":"iichen","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"iichen"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/iichen.cn\/?p=409#article","isPartOf":{"@id":"https:\/\/iichen.cn\/?p=409"},"author":{"name":"iichen","@id":"https:\/\/iichen.cn\/#\/schema\/person\/4a47edf85ab49841df9e8f6aee40b77c"},"headline":"kotlin-\u534f\u7a0b","datePublished":"2022-11-24T08:11:45+00:00","mainEntityOfPage":{"@id":"https:\/\/iichen.cn\/?p=409"},"wordCount":40,"commentCount":0,"publisher":{"@id":"https:\/\/iichen.cn\/#\/schema\/person\/4a47edf85ab49841df9e8f6aee40b77c"},"image":{"@id":"https:\/\/iichen.cn\/?p=409#primaryimage"},"thumbnailUrl":"https:\/\/p3-juejin.byteimg.com\/tos-cn-i-k3u1fbpfcp\/60453cfebece44779b6581aefef14284~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image","articleSection":["Android","\u7b14\u8bb0"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/iichen.cn\/?p=409#respond"]}]},{"@type":"WebPage","@id":"https:\/\/iichen.cn\/?p=409","url":"https:\/\/iichen.cn\/?p=409","name":"kotlin-\u534f\u7a0b - IIchen","isPartOf":{"@id":"https:\/\/iichen.cn\/#website"},"primaryImageOfPage":{"@id":"https:\/\/iichen.cn\/?p=409#primaryimage"},"image":{"@id":"https:\/\/iichen.cn\/?p=409#primaryimage"},"thumbnailUrl":"https:\/\/p3-juejin.byteimg.com\/tos-cn-i-k3u1fbpfcp\/60453cfebece44779b6581aefef14284~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image","datePublished":"2022-11-24T08:11:45+00:00","breadcrumb":{"@id":"https:\/\/iichen.cn\/?p=409#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/iichen.cn\/?p=409"]}]},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/iichen.cn\/?p=409#primaryimage","url":"https:\/\/p3-juejin.byteimg.com\/tos-cn-i-k3u1fbpfcp\/60453cfebece44779b6581aefef14284~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image","contentUrl":"https:\/\/p3-juejin.byteimg.com\/tos-cn-i-k3u1fbpfcp\/60453cfebece44779b6581aefef14284~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image"},{"@type":"BreadcrumbList","@id":"https:\/\/iichen.cn\/?p=409#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/iichen.cn\/"},{"@type":"ListItem","position":2,"name":"kotlin-\u534f\u7a0b"}]},{"@type":"WebSite","@id":"https:\/\/iichen.cn\/#website","url":"https:\/\/iichen.cn\/","name":"IIchen","description":"Just do it!","publisher":{"@id":"https:\/\/iichen.cn\/#\/schema\/person\/4a47edf85ab49841df9e8f6aee40b77c"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/iichen.cn\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-Hans"},{"@type":["Person","Organization"],"@id":"https:\/\/iichen.cn\/#\/schema\/person\/4a47edf85ab49841df9e8f6aee40b77c","name":"iichen","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/iichen.cn\/#\/schema\/person\/image\/","url":"https:\/\/iichen.cn\/wp-content\/uploads\/2025\/01\/avatar.jpg","contentUrl":"https:\/\/iichen.cn\/wp-content\/uploads\/2025\/01\/avatar.jpg","width":940,"height":940,"caption":"iichen"},"logo":{"@id":"https:\/\/iichen.cn\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/www.iichen.cn"],"url":"https:\/\/iichen.cn\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/iichen.cn\/index.php?rest_route=\/wp\/v2\/posts\/409","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/iichen.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/iichen.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/iichen.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/iichen.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=409"}],"version-history":[{"count":0,"href":"https:\/\/iichen.cn\/index.php?rest_route=\/wp\/v2\/posts\/409\/revisions"}],"wp:attachment":[{"href":"https:\/\/iichen.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=409"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/iichen.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=409"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/iichen.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=409"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}