{"id":953,"date":"2026-01-25T07:40:12","date_gmt":"2026-01-25T07:40:12","guid":{"rendered":"https:\/\/nurlandroid.com\/?p=953"},"modified":"2026-01-25T07:40:13","modified_gmt":"2026-01-25T07:40:13","slug":"%d0%b2-%d1%87%d1%91%d0%bc-%d1%80%d0%b0%d0%b7%d0%bd%d0%b8%d1%86%d0%b0-%d0%bc%d0%b5%d0%b6%d0%b4%d1%83-flow-stateflow-sharedflow-%d0%b8-channel","status":"publish","type":"post","link":"https:\/\/nurlandroid.com\/?p=953","title":{"rendered":"\u0412 \u0447\u0451\u043c \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 flow{}, StateFlow, SharedFlow \u0438 Channel?"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\"><code>Flow {}<\/code> \u2014 <strong>\u0445\u043e\u043b\u043e\u0434\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a<\/strong><\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nfun getFlow(): Flow&amp;lt;Int&gt; = flow {\n    emit(1)\n    emit(2)\n}\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li>\u0421\u0442\u0430\u0440\u0442\u0443\u0435\u0442 <strong>\u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 collect<\/strong><\/li>\n\n\n\n<li>\u041a\u0430\u0436\u0434\u044b\u0439 <code>collector<\/code> \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 <strong>\u0441\u0432\u043e\u044e \u043a\u043e\u043f\u0438\u044e<\/strong><\/li>\n\n\n\n<li>\u041f\u043e\u043b\u0435\u0437\u0435\u043d \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0411\u0414, API)<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><code>StateFlow<\/code> \u2014 <strong>\u0433\u043e\u0440\u044f\u0447\u0438\u0439 \u043f\u043e\u0442\u043e\u043a \u0441 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c<\/strong><\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nval state = MutableStateFlow(0)\nstate.value = 1\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li>\u041f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0430\u043a\u0442\u0438\u0432\u0435\u043d<\/li>\n\n\n\n<li><strong>\u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/strong><\/li>\n\n\n\n<li>\u041a\u0430\u0436\u0434\u044b\u0439 \u043d\u043e\u0432\u044b\u0439 \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 <strong>\u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435<\/strong><\/li>\n\n\n\n<li>\u0410\u043d\u0430\u043b\u043e\u0433 <code>LiveData<\/code>, \u043d\u043e \u0432 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u043d\u043e\u043c \u0441\u0442\u0438\u043b\u0435<\/li>\n\n\n\n<li>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 ViewModel \u0434\u043b\u044f UI-\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><code>SharedFlow<\/code> \u2014 <strong>\u0433\u043e\u0440\u044f\u0447\u0438\u0439 \u043f\u043e\u0442\u043e\u043a \u0434\u043b\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0439<\/strong><\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nval shared = MutableSharedFlow&amp;lt;Int&gt;(replay = 1)\nshared.emit(42)\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li>\u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0430\u043a <strong>broadcast<\/strong><\/li>\n\n\n\n<li>\u041c\u043e\u0436\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c <code>replay<\/code> \u0438 \u0431\u0443\u0444\u0435\u0440<\/li>\n\n\n\n<li>\u041f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 <strong>\u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0435<\/strong>, \u0435\u0441\u043b\u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043b\u0438\u0441\u044c \u043f\u043e\u0437\u0434\u043d\u043e (\u0435\u0441\u043b\u0438 <code>replay=0<\/code>)<\/li>\n\n\n\n<li>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0440\u0430\u0437\u043e\u0432\u044b\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439: \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u044f, \u0442\u043e\u0441\u0442\u044b, \u043e\u0448\u0438\u0431\u043a\u0438<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><code>Channel<\/code> \u2014 <strong>\u0434\u0432\u0443\u0441\u0442\u043e\u0440\u043e\u043d\u043d\u044f\u044f \u0442\u0440\u0443\u0431\u0430<\/strong><\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nval channel = Channel&amp;lt;Int&gt;()\nlaunch { channel.send(1) }\nlaunch { val x = channel.receive() }\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li>\u0421\u043b\u0443\u0436\u0438\u0442 \u043a\u0430\u043a <strong>\u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439<\/strong> \u043c\u0435\u0436\u0434\u0443 coroutine producer \u2194 consumer<\/li>\n\n\n\n<li>\u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0430\u043a &#171;mailbox&#187;<\/li>\n\n\n\n<li><code>send()<\/code> <strong>\u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f<\/strong>, \u0435\u0441\u043b\u0438 \u0431\u0443\u0444\u0435\u0440 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d (\u0438\u043b\u0438 \u043d\u0438\u043a\u0442\u043e \u043d\u0435 <code>receive<\/code>)<\/li>\n\n\n\n<li>\u041f\u043e\u0441\u043b\u0435 <code>receive()<\/code> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0441\u0447\u0435\u0437\u0430\u0435\u0442<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Flow {} \u2014 \u0445\u043e\u043b\u043e\u0434\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a StateFlow \u2014 \u0433\u043e\u0440\u044f\u0447\u0438\u0439 \u043f\u043e\u0442\u043e\u043a \u0441 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c SharedFlow \u2014 \u0433\u043e\u0440\u044f\u0447\u0438\u0439 \u043f\u043e\u0442\u043e\u043a \u0434\u043b\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0439 Channel \u2014 \u0434\u0432\u0443\u0441\u0442\u043e\u0440\u043e\u043d\u043d\u044f\u044f \u0442\u0440\u0443\u0431\u0430<\/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-953","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\/953","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=953"}],"version-history":[{"count":1,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/posts\/953\/revisions"}],"predecessor-version":[{"id":954,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/posts\/953\/revisions\/954"}],"wp:attachment":[{"href":"https:\/\/nurlandroid.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=953"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=953"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=953"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}