{"id":543,"date":"2022-08-27T08:12:52","date_gmt":"2022-08-27T08:12:52","guid":{"rendered":"https:\/\/nurlandroid.com\/?p=543"},"modified":"2022-08-28T13:07:53","modified_gmt":"2022-08-28T13:07:53","slug":"continuation-%d0%bd%d0%b5-%d0%bc%d0%b0%d0%b3%d0%b8%d1%8f-%d0%ba%d0%be%d1%80%d1%83%d1%82%d0%b8%d0%bd","status":"publish","type":"post","link":"https:\/\/nurlandroid.com\/?p=543","title":{"rendered":"Continuation. \u041d\u0435 &#171;\u041c\u0430\u0433\u0438\u044f&#187; \u043a\u043e\u0440\u0443\u0442\u0438\u043d"},"content":{"rendered":"\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0442\u043e \u043a\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043d\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u0442\u043e\u043a\u0430 \u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u043a\u043e\u043b\u0431\u044d\u043a\u043e\u0432 &#171;\u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c&#187;. \u0415\u0441\u043b\u0438 \u0447\u0435\u0441\u0442\u043d\u043e, \u0442\u043e \u043a\u043e\u043b\u0431\u044d\u043a\u0438 \u0432\u0441\u0435 \u0436\u0435 \u0435\u0441\u0442\u044c=) \u041d\u0435 \u0432\u0441\u0435 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e, \u043d\u043e \u0438 \u043d\u0435 \u0441\u043b\u043e\u0436\u043d\u043e! \u041a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c <strong>Continuation<\/strong>.<\/p>\n\n\n\n<p><strong>Continuation<\/strong> \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u043a\u043e\u043b\u0431\u044d\u043a. <strong>Continuation<\/strong> &#8212; \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 \u043e\u0433\u0440\u043e\u043c\u043d\u0443\u044e \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u0443, \u0433\u0434\u0435 \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u043a\u0443\u0441\u043e\u043a \u041a\u043e\u0440\u0443\u0442\u0438\u043d-\u043a\u043e\u0434\u0430(Suspend-\u0444\u0443\u043d\u043a\u0446\u0438\u0438) \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0439 <strong>Switch-Case<\/strong>.<\/p>\n\n\n\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0443\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>launch {\n\tval url = \"http:\/\/myurl.com\/file.pdf\"\n\n\t\/\/ long synchronous function\n\tsuspendedGetFile(url)\n\n\tprintln(\"File is downloaded\")\n}<\/code><\/pre>\n\n\n\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 Java \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f Kotlin \u043a\u043e\u0434\u0430 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class GeneratedContinuationClass extends SuspendLambda {\n\n    int label;\n    String url;\n\n    void invokeSuspend() {\n        switch (label) {\n            case 0: {  \/\/ \u0448\u0430\u0433 1-\u044b\u0439\n                url = buildUrl();\n                label = 1;\n\n                suspendedGetFile(url, this);  \/\/ \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \"this\". \u0415\u0433\u043e \u043d\u0435 \u0431\u044b\u043b\u043e \u0432 Kotlin \u0432\u0435\u0440\u0441\u0438\u0438\n                return;\n            }              \/\/ &lt;= \u041f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0443\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u043e\u0434\u043e\u0440\u0430\u0437\u0434\u0435\u043b \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430. \u0414\u043e \u0441\u0442\u0430\u0440\u0442\u0430 suspend-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u043f\u043e\u0441\u043b\u0435\n            case 1: {  \/\/ \u0448\u0430\u0433 2-\u043e\u0439\n                println(\"File is downloaded\");\n                return;\n            }\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u0417\u0430\u043c\u0435\u0442\u044c\u0442\u0435, \u0447\u0442\u043e \u043d\u0430\u0448\u0430 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043b\u0430\u0441\u044c \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043c\u0435\u0442\u043e\u0434 <strong>invokeSuspend()<\/strong>, \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <strong>label<\/strong> \u0438 \u043d\u0430 \u0442\u043e \u043a\u0430\u043a \u043e\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 <strong>switch<\/strong>-\u0435. \u041a\u0430\u043a \u0432\u044b \u0443\u0441\u043f\u0435\u043b\u0438 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043e\u0434 \u043d\u0430\u0448\u0435\u0439 \u041a\u043e\u0440\u0443\u0442\u0438\u043d\u044b(buildUrl(),suspendedGetFile(), println()) \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 <strong>invokeSuspend()<\/strong>. \u041e\u043d \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u041a\u043e\u0440\u0443\u0442\u0438\u043d\u044b.<\/p>\n\n\n\n<p><strong>Continuation<\/strong> \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u0434 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u043f\u043e\u0441\u043b\u0435 <strong>suspendedGetFile()<\/strong> &#8212; \u0430 \u044d\u0442\u043e <strong>println()<\/strong> &#8212; \u0431\u044b\u043b \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f <strong>supendedGetFile()<\/strong>. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0434 \u0434\u0435\u043b\u0438\u0442\u0441\u044f <strong>switch<\/strong>-\u0435\u043c \u043d\u0430 \u0434\u0432\u0435 \u0447\u0430\u0441\u0442\u0438 \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <strong>label<\/strong>. \u0422\u043e\u0447\u043a\u0430 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430 \u043d\u0430 \u0434\u0432\u0435 \u0447\u0430\u0441\u0442\u0438 &#8212; \u044d\u0442\u043e <strong>suspend-\u0444\u0443\u043d\u043a\u0446\u0438\u044f<\/strong>.<\/p>\n\n\n\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 <strong>Continuation<\/strong> &#8212; \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u0434, \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <strong>download()<\/strong>, \u0431\u044b\u043b \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u0433\u0434\u0430 \u043c\u0435\u0442\u043e\u0434 <strong>download()<\/strong> \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b \u0440\u0430\u0431\u043e\u0442\u0443. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0434 \u0434\u0435\u043b\u0438\u0442\u0441\u044f <strong>switch<\/strong>-\u0435\u043c \u043d\u0430 \u0434\u0432\u0435 \u0447\u0430\u0441\u0442\u0438. \u0418 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <strong>label<\/strong>. \u0422\u043e\u0447\u043a\u0430 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430 \u043d\u0430 \u0434\u0432\u0435 \u0447\u0430\u0441\u0442\u0438 &#8212; \u044d\u0442\u043e <strong>suspend-\u0444\u0443\u043d\u043a\u0446\u0438\u044f<\/strong>. \u041e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <strong>label<\/strong> \u0437\u0430\u0432\u0438\u0441\u0438\u0442, \u043a\u0430\u043a\u0430\u044f \u0438\u0437 \u0434\u0432\u0443\u0445 \u0447\u0430\u0441\u0442\u0435\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0430 \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 <strong>invokeSuspend()<\/strong>. \u0412 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 <strong>invokeSuspend()<\/strong> \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d 2 \u0440\u0430\u0437\u0430. \u041a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u0441\u043b\u043e\u0432\u0430 &#171;case&#187; \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0442\u043e\u0438\u0442 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u043a\u0430\u043a &#171;\u0448\u0430\u0433\u0438&#187;<\/p>\n\n\n\n<p>\u0418\u0442\u0430\u043a, \u043f\u0435\u0440\u0432\u044b\u0439 \u0440\u0430\u0437 <strong>invokeSuspend()<\/strong> \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d \u043f\u0440\u0438 \u0441\u0442\u0430\u0440\u0442\u0435 \u041a\u043e\u0440\u0443\u0442\u0438\u043d\u044b. \u041e\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442 \u0431\u043b\u043e\u043a \u043a\u043e\u0434\u0430 \u0432 <strong>case0<\/strong>: \u043f\u043e\u043c\u0435\u043d\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <strong>label<\/strong> \u043d\u0430 1 \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442 <strong>suspend-\u0444\u0443\u043d\u043a\u0446\u0438\u044e<\/strong>. \u0412\u0442\u043e\u0440\u043e\u0439 \u0440\u0430\u0437 <strong>invokeSuspend()<\/strong> \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d \u0443\u0436\u0435 \u0438\u0437 \u043d\u0430\u0448\u0435\u0439 <strong>suspend-\u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/strong> <strong>suspendedGetFile()<\/strong>, \u043a\u043e\u0433\u0434\u0430 \u043e\u043d\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442 \u0441\u0432\u043e\u044e \u0440\u0430\u0431\u043e\u0442\u0443. \u041a\u0430\u043a \u0442\u0430\u043a?=) <strong>Suspend-\u0444\u0443\u043d\u043a\u0446\u0438\u044f<\/strong> \u043f\u0440\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0432 Java \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0441 \u0442\u0438\u043f\u043e\u043c <strong>Continuation<\/strong>. \u0422.\u0435. \u0432 <strong>suspend-\u0444\u0443\u043d\u043a\u0446\u0438\u044e suspendedGetFile()<\/strong> \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0438\u043d\u0441\u0442\u0430\u043d\u0441 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e <strong>Continuation<\/strong>-\u0430 &#8212; <strong>this<\/strong>.<\/p>\n\n\n\n<p>\u041a\u043e\u0433\u0434\u0430 <strong>suspend-\u0444\u0443\u043d\u043a\u0446\u0438\u044f suspendedGetFile()<\/strong> \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0444\u0430\u0439\u043b\u0430, \u043e\u043d\u0430 \u0432\u043e\u0437\u044c\u043c\u0435\u0442 <strong>Continuation<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0435\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u043b\u0438 \u0438 \u0432\u044b\u0437\u043e\u0432\u0435\u0442 \u0435\u0433\u043e <strong>invokeSuspend<\/strong>() \u043c\u0435\u0442\u043e\u0434. <strong>label<\/strong> \u0431\u044b\u043b \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u0432 1 (\u0435\u0449\u0435 \u0434\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430 suspend \u0444\u0443\u043d\u043a\u0446\u0438\u0438), \u043f\u043e\u044d\u0442\u043e\u043c\u0443 <strong>switch<\/strong> \u043f\u043e\u0439\u0434\u0435\u0442 \u0432\u043e \u0432\u0442\u043e\u0440\u0443\u044e \u0432\u0435\u0442\u043a\u0443 \u0438 \u043c\u0435\u0442\u043e\u0434 <strong>toast<\/strong> \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d.<\/p>\n\n\n\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c <strong>Continuation<\/strong> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043b\u0431\u044d\u043a\u043e\u043c \u0434\u043b\u044f <strong>suspend-\u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/strong>. \u0415\u0441\u043b\u0438 \u0432 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0435 \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e <strong>suspend-\u0444\u0443\u043d\u043a\u0446\u0438\u0439<\/strong>, \u0442\u043e <strong>Continuation<\/strong> \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u043b\u0431\u044d\u043a\u043e\u043c \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043d\u0438\u0445.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>\u0412\u043e\u0437\u0432\u0440\u0430\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f suspend-\u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439<\/strong><br><strong>Suspend-\u0444\u0443\u043d\u043a\u0446\u0438\u044f<\/strong> \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043a\u0430\u043a\u043e\u0435-\u043b\u0438\u0431\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043a\u0430\u043a \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441\u0432\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u044d\u0442\u0430 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 <strong>Continuation<\/strong>.<\/p>\n\n\n\n<p>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u043c \u043a\u043e\u0434:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>launch {\n\tval url = \"http:\/\/myurl.com\/file.pdf\"\n\n\t\/\/ long synchronous function\n\tval file = suspendedGetFile(url)\n\n\tprintln(\"File is downloaded\")\n\n\tval size = suspendUnzip(file)\n\n\tprintln(\"Size is $size\")\n}<\/code><\/pre>\n\n\n\n<p>\u041c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0435\u0449\u0435 \u043e\u0434\u043d\u0443 <strong>suspend-\u0444\u0443\u043d\u043a\u0446\u0438\u044e suspendUnzip()<\/strong>. \u041f\u0440\u0438 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430 \u0432 Java, \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d \u043d\u0430 \u0442\u0440\u0438 \u0447\u0430\u0441\u0442\u0438:<br>1) <strong>suspendedGetFile<\/strong>() \u0438 \u0432\u0441\u0435, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u0434 \u043d\u0435\u0439<br>2) <strong>suspendUnzip<\/strong>() \u0438 \u0432\u0441\u0435, \u0447\u0442\u043e \u043c\u0435\u0436\u0434\u0443 \u043d\u0435\u0439 \u0438 <strong>suspendedGetFile()<\/strong><br>3) \u0432\u0441\u0435, \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435 <strong>suspendUnzip<\/strong>()<\/p>\n\n\n\n<p>\u0422\u043e\u0447\u043a\u0438 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f &#8212; \u044d\u0442\u043e <strong>suspend-\u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>File file;\nLong size;\n\nvoid invokeSuspend(Object result) {\n    switch (label) {\n        case 0: {\n            url = buildUrl();\n            label = 1;\n\n            suspendedGetFile(url, this);\n            return;\n        }\n        case 1: {\n            file = (File) result;\n            println(\"File is downloaded\");\n            label = 2;\n\n            suspendUnzip(file, this);\n            return;\n        }\n        case 2: {\n            size = (Long) result\n            toast(\"File is unzipped, size = \" + size);\n            return;\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u041a\u0430\u043a \u043c\u044b \u0440\u0430\u043d\u0435\u0435 \u0443\u0436\u0435 \u043e\u0431\u0441\u0443\u0434\u0438\u043b\u0438, <strong>suspend-\u0444\u0443\u043d\u043a\u0446\u0438\u044f<\/strong> \u043f\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 \u0441\u0432\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 <strong>invokeSuspend()<\/strong>. \u0418 \u0438\u043c\u0435\u043d\u043d\u043e \u0441\u044e\u0434\u0430 \u0436\u0435 \u043e\u043d\u0430 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441\u0432\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0443 <strong>invokeSuspend()<\/strong> \u0435\u0441\u0442\u044c \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0442\u0438\u043f\u0430 <strong>Object<\/strong>.<\/p>\n\n\n\n<p><strong>Suspend-\u0444\u0443\u043d\u043a\u0446\u0438\u044f<\/strong> <strong>suspendedGetFile()<\/strong> \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 <strong>invokeSuspend()<\/strong> \u043f\u0435\u0440\u0435\u0434\u0430\u0441\u0442 \u0444\u0430\u0439\u043b <strong>(File)<\/strong>. \u0410 \u0432 \u0432\u0435\u0442\u043a\u0435 case 1 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u0430 <strong>Object<\/strong> \u043a \u0442\u0438\u043f\u0443 <strong>File<\/strong>.<\/p>\n\n\n\n<p><strong>Suspend-\u0444\u0443\u043d\u043a\u0446\u0438\u044f suspendUnzip()<\/strong> \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 <strong>invokeSuspend()<\/strong> \u043f\u0435\u0440\u0435\u0434\u0430\u0441\u0442 \u0440\u0430\u0437\u043c\u0435\u0440 <strong>(Long)<\/strong>. \u0410 \u0432 \u0432\u0435\u0442\u043a\u0435 case 2 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u0430 <strong>Object<\/strong> \u043a \u0442\u0438\u043f\u0443 <strong>Long<\/strong>.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0442\u043e \u043a\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043d\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u0442\u043e\u043a\u0430 \u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u043a\u043e\u043b\u0431\u044d\u043a\u043e\u0432 &#171;\u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c&#187;. \u0415\u0441\u043b\u0438 \u0447\u0435\u0441\u0442\u043d\u043e, \u0442\u043e \u043a\u043e\u043b\u0431\u044d\u043a\u0438 \u0432\u0441\u0435 \u0436\u0435 \u0435\u0441\u0442\u044c=) \u041d\u0435 \u0432\u0441\u0435 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e, \u043d\u043e \u0438 \u043d\u0435 \u0441\u043b\u043e\u0436\u043d\u043e! \u041a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c Continuation. Continuation \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u043a\u043e\u043b\u0431\u044d\u043a. Continuation &#8212; \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 \u043e\u0433\u0440\u043e\u043c\u043d\u0443\u044e \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u0443, \u0433\u0434\u0435 \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u043a\u0443\u0441\u043e\u043a \u041a\u043e\u0440\u0443\u0442\u0438\u043d-\u043a\u043e\u0434\u0430(Suspend-\u0444\u0443\u043d\u043a\u0446\u0438\u0438) \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0439 Switch-Case. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,23,21],"tags":[],"class_list":["post-543","post","type-post","status-publish","format-standard","hentry","category-android","category-coroutines","category-kotlin"],"_links":{"self":[{"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/posts\/543","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=543"}],"version-history":[{"count":1,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/posts\/543\/revisions"}],"predecessor-version":[{"id":544,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/posts\/543\/revisions\/544"}],"wp:attachment":[{"href":"https:\/\/nurlandroid.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=543"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=543"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=543"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}