{"id":957,"date":"2026-01-25T08:05:22","date_gmt":"2026-01-25T08:05:22","guid":{"rendered":"https:\/\/nurlandroid.com\/?p=957"},"modified":"2026-01-25T08:05:23","modified_gmt":"2026-01-25T08:05:23","slug":"%d0%ba%d0%b0%d0%ba-%d0%be%d1%82%d0%bc%d0%b5%d0%bd%d1%8f%d0%b5%d1%82%d1%81%d1%8f-flow-%d1%87%d1%82%d0%be-%d0%bf%d1%80%d0%be%d0%b8%d1%81%d1%85%d0%be%d0%b4%d0%b8%d1%82-%d0%bf%d1%80%d0%b8-%d0%be%d1%82","status":"publish","type":"post","link":"https:\/\/nurlandroid.com\/?p=957","title":{"rendered":"\u041a\u0430\u043a \u043e\u0442\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f Flow? \u0427\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u0438 \u043e\u0442\u043c\u0435\u043d\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0438\u0434\u0451\u0442 collect?"},"content":{"rendered":"\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u0432\u0441\u0451 \u043f\u043e \u0448\u0430\u0433\u0430\u043c. \u0427\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u0435\u0441\u043b\u0438 \u043e\u0442\u043c\u0435\u043d\u0438\u0442\u044c \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443, \u0433\u0434\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 <code>collect()<\/code>?<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nval job = scope.launch {\n    flow.collect { value -&gt;\n        println(&quot;Value: $value&quot;)\n    }\n}\njob.cancel()\n<\/pre><\/div>\n\n\n<p>\u041f\u0440\u0438 \u043e\u0442\u043c\u0435\u043d\u0435:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u041e\u0442\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f <strong><code>CoroutineScope<\/code> \/ <code>Job<\/code><\/strong><\/li>\n\n\n\n<li>\u041e\u0442\u043c\u0435\u043d\u0430 <strong>\u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 <code>collect {}<\/code><\/strong><\/li>\n\n\n\n<li>\u0412\u043d\u0443\u0442\u0440\u0438 <code>flow {}<\/code> \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <strong><code>CancellationException<\/code><\/strong><\/li>\n\n\n\n<li>\u0412\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 <strong>\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e<\/strong> (\u0435\u0441\u043b\u0438 \u0442\u044b \u043d\u0435 \u043f\u043e\u0434\u0430\u0432\u0438\u043b \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435)<\/li>\n\n\n\n<li>\u0420\u0435\u0441\u0443\u0440\u0441\u044b \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u044e\u0442\u0441\u044f (\u0435\u0441\u043b\u0438 <code>finally {}<\/code> \/ <code>onCompletion {}<\/code>)<\/li>\n<\/ol>\n\n\n\n<h4 class=\"wp-block-heading\">\u041a\u0430\u043a <code>Flow<\/code> \u0443\u0437\u043d\u0430\u0451\u0442, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f?<\/h4>\n\n\n\n<p>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>collect {}<\/code> \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 <code>coroutineContext.isActive<\/code><\/li>\n\n\n\n<li><code>emit()<\/code> \u0442\u043e\u0436\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u0442\u0430\u043a\u0443\u044e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443<\/li>\n\n\n\n<li>\u0435\u0441\u043b\u0438 \u043e\u0442\u043c\u0435\u043d\u0435\u043d\u043e \u2192 \u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f <code>CancellationException<\/code><\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">\u0412\u0430\u0436\u043d\u043e: <code>flow {}<\/code> \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c <strong>cancellation-cooperative<\/strong><\/h4>\n\n\n\n<p>\u0421ancellation-cooperative &#8212; \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 <code>flow<\/code><\/th><th>\u0420\u0435\u0430\u043a\u0446\u0438\u044f \u043d\u0430 \u043e\u0442\u043c\u0435\u043d\u0443 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b<\/th><\/tr><\/thead><tbody><tr><td><code>delay()<\/code>, <code>emit()<\/code>, <code>collect()<\/code><\/td><td>\u0425\u043e\u0440\u043e\u0448\u043e: \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438. \u041e\u043d\u0438 \u0421ancellation-cooperative<\/td><\/tr><tr><td><code>Thread.sleep()<\/code><\/td><td>\u041f\u043b\u043e\u0445\u043e: \u043d\u0435 \u043f\u0440\u0435\u0440\u0432\u0451\u0442\u0441\u044f, \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u043f\u043e\u0442\u043e\u043a<\/td><\/tr><tr><td><code>while(true) {}<\/code><\/td><td>\u041f\u043b\u043e\u0445\u043e: \u0437\u0430\u0446\u0438\u043a\u043b\u0438\u0442, \u0431\u0435\u0437 \u0432\u044b\u0445\u043e\u0434\u0430<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u0432\u0441\u0451 \u043f\u043e \u0448\u0430\u0433\u0430\u043c. \u0427\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u0435\u0441\u043b\u0438 \u043e\u0442\u043c\u0435\u043d\u0438\u0442\u044c \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443, \u0433\u0434\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 collect()? \u041f\u0440\u0438 \u043e\u0442\u043c\u0435\u043d\u0435: \u041a\u0430\u043a Flow \u0443\u0437\u043d\u0430\u0451\u0442, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f? \u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438: \u0412\u0430\u0436\u043d\u043e: flow {} \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c cancellation-cooperative \u0421ancellation-cooperative &#8212; \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. \u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 flow \u0420\u0435\u0430\u043a\u0446\u0438\u044f \u043d\u0430 \u043e\u0442\u043c\u0435\u043d\u0443 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b delay(), emit(), collect() \u0425\u043e\u0440\u043e\u0448\u043e: \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438. \u041e\u043d\u0438 \u0421ancellation-cooperative [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,21],"tags":[],"class_list":["post-957","post","type-post","status-publish","format-standard","hentry","category-coroutines","category-kotlin"],"_links":{"self":[{"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/posts\/957","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=957"}],"version-history":[{"count":2,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/posts\/957\/revisions"}],"predecessor-version":[{"id":959,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/posts\/957\/revisions\/959"}],"wp:attachment":[{"href":"https:\/\/nurlandroid.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=957"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=957"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=957"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}