{"id":150519,"date":"2021-06-04T09:00:00","date_gmt":"2021-06-04T08:00:00","guid":{"rendered":"https:\/\/blog.jetbrains.com\/kotlin\/2021\/05\/kotlin-coroutines-1-5-0-released\/"},"modified":"2021-06-04T12:02:34","modified_gmt":"2021-06-04T11:02:34","slug":"kotlin-coroutines-1-5-0-released","status":"publish","type":"kotlin","link":"https:\/\/blog.jetbrains.com\/ru\/kotlin\/2021\/06\/kotlin-coroutines-1-5-0-released\/","title":{"rendered":"\u041a\u043e\u0440\u0443\u0442\u0438\u043d\u044b 1.5 \u0432 Kotlin: GlobalScope \u043e\u0442\u043c\u0435\u0447\u0435\u043d \u043a\u0430\u043a \u00ab\u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u0439 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f\u00bb, \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u044b\u0439 Channels API \u0438 \u043c\u043d\u043e\u0433\u043e\u0435 \u0434\u0440\u0443\u0433\u043e\u0435"},"content":{"rendered":"<p><em>\u0421\u043e\u0430\u0432\u0442\u043e\u0440: <a class=\"ek-link\" href=\"https:\/\/blog.jetbrains.com\/author\/svetlana-isakova\/\">\u0421\u0432\u0435\u0442\u043b\u0430\u043d\u0430 \u0418\u0441\u0430\u043a\u043e\u0432\u0430<\/a><\/em><\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b 1.5.0! \u0412\u043e\u0442 \u0447\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e \u0432 \u043d\u043e\u0432\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438.<\/p>\n<ul>\n<li><a class=\"ek-link\" href=\"https:\/\/blog.jetbrains.com\/kotlin\/2021\/05\/kotlin-coroutines-1-5-0-released\/#globalscope\">\u041a\u043b\u0430\u0441\u0441 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 GlobalScope \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u0442\u043c\u0435\u0447\u0435\u043d \u043a\u0430\u043a API, \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u0439 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f.<\/a> GlobalScope \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043b\u0435\u0433\u043a\u043e \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443. \u0422\u0435\u043f\u0435\u0440\u044c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0434\u0438\u0442 \u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0435, \u0430 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435.<\/li>\n<\/ul>\n<ul>\n<li><a class=\"ek-link\" href=\"https:\/\/blog.jetbrains.com\/kotlin\/2021\/05\/kotlin-coroutines-1-5-0-released\/#junit\">\u0420\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0434\u043b\u044f JUnit.<\/a> \u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f CoroutinesTimeout \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u0434\u043b\u044f \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 JUnit 5.<\/li>\n<\/ul>\n<ul>\n<li><a class=\"ek-link\" href=\"https:\/\/blog.jetbrains.com\/kotlin\/2021\/05\/kotlin-coroutines-1-5-0-released\/#channels\">\u0423\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u044b\u0439 Channels API.<\/a> \u041f\u043e\u043c\u0438\u043c\u043e \u043d\u043e\u0432\u044b\u0445 \u043f\u0440\u0430\u0432\u0438\u043b \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0431\u044b\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u043d\u0435\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>trySend<\/code> \u0438 <code>tryReceive<\/code>, \u0441\u0442\u0430\u0432\u0448\u0438\u0435 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u043e\u0439 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043e\u0439 \u0434\u043b\u044f <code>offer<\/code> \u0438 <code>poll<\/code>.<\/li>\n<\/ul>\n<ul>\n<li><a class=\"ek-link\" href=\"https:\/\/blog.jetbrains.com\/kotlin\/2021\/05\/kotlin-coroutines-1-5-0-released\/#reactive\">\u0421\u0442\u0430\u0431\u0438\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 \u0441 \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c\u0438 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438.<\/a> \u041c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043d\u043e\u0432\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432 \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0432 Kotlin Flow \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e, \u0430 \u0437\u0430\u043e\u0434\u043d\u043e \u0441\u0442\u0430\u0431\u0438\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438 ReactiveContext API.<\/li>\n<\/ul>\n<p>\u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0432\u044b \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0438 \u043f\u043e \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u043d\u0430 \u043d\u043e\u0432\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e.<\/p>\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\">\n<div class=\"wp-block-embed__wrapper\"><iframe loading=\"lazy\" title=\"Kotlin Coroutines 1.5: GlobalScope \u043e\u0442\u043c\u0435\u0447\u0435\u043d \u043a\u0430\u043a \u00ab\u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u0439 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f\u00bb, \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u044b\u0439 Channels API \u0438 \u043c\u043d\u043e\u0433\u043e\u0435 \u0434\u0440\u0443\u0433\u043e\u0435\" src=\"https:\/\/www.youtube.com\/embed\/EVLnWOcR0is?feature=oembed\" width=\"500\" height=\"281\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/div>\n<\/figure>\n<p align=\"center\"><a class=\"ek-link jb-download-button\" title=\"\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b 1.5.0\" href=\"https:\/\/blog.jetbrains.com\/kotlin\/2021\/05\/kotlin-coroutines-1-5-0-released\/#use-coroutines-1-5-0\">\u041d\u0430\u0447\u043d\u0438\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b 1.5.0<\/a><\/p>\n<h1 id=\"globalscope\">GlobalScope \u043e\u0442\u043c\u0435\u0447\u0435\u043d \u043a\u0430\u043a API, \u00ab\u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u0439 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f\u00bb<\/h1>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043a\u043b\u0430\u0441\u0441 <code>GlobalScope<\/code> \u043e\u0442\u043c\u0435\u0447\u0435\u043d \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439 <code>@DelicateCoroutinesApi<\/code>. \u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u044d\u0442\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438, \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <code>GlobalScope<\/code> \u0435\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u044f\u0432\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e <code>@OptIn(DelicateCoroutinesApi::class)<\/code>.<\/p>\n<p>\u0412 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>GlobalScope<\/code> \u043d\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f, \u043e\u0434\u043d\u0430\u043a\u043e <a href=\"https:\/\/kotlinlang.org\/docs\/coroutines-basics.html#your-first-coroutine\" target=\"_blank\" rel=\"noopener\">\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f<\/a> \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u0440\u044f\u0434 \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u043e\u0432 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u044d\u0442\u043e\u0433\u043e API.<\/p>\n<p>\u0413\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0430\u044f \u043e\u0431\u043b\u0430\u0441\u0442\u044c <code>CoroutineScope<\/code> \u043d\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u0430 \u043d\u0438 \u0441 \u043a\u0430\u043a\u0438\u043c \u0437\u0430\u0434\u0430\u043d\u0438\u0435\u043c. \u0422\u0430\u043a\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043a\u043e\u0440\u0443\u0442\u0438\u043d \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0433\u043e \u0441\u0440\u043e\u043a\u0430 \u0436\u0438\u0437\u043d\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0410\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b, \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0435 \u0432 <code>GlobalScope<\/code>, \u043d\u0435 \u043f\u0440\u0435\u043f\u044f\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430. \u041e\u043d\u0438 \u043f\u043e\u0445\u043e\u0436\u0438 \u043d\u0430 \u043f\u043e\u0442\u043e\u043a\u0438-\u0434\u0435\u043c\u043e\u043d\u044b \u0432 Java.<\/p>\n<p>\u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 API <code>GlobalScope<\/code> \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0443\u0442\u0435\u0447\u043a\u0443 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0438\u043b\u0438 \u043f\u0430\u043c\u044f\u0442\u0438. \u041a\u043e\u0440\u0443\u0442\u0438\u043d\u044b, \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0435 \u0432 <code>GlobalScope<\/code>, \u043d\u0435 \u043f\u043e\u0434\u0447\u0438\u043d\u044f\u044e\u0442\u0441\u044f \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0437\u043c\u0430. \u0415\u0441\u043b\u0438 \u043e\u043d\u0438 \u0437\u0430\u0432\u0438\u0441\u0430\u044e\u0442 \u0438\u043b\u0438 \u0442\u043e\u0440\u043c\u043e\u0437\u044f\u0442 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0438\u0437-\u0437\u0430 \u043d\u0438\u0437\u043a\u043e\u0439 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043d\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0441\u0435\u0442\u0438), \u0442\u043e \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u044b. \u0412\u043e\u0437\u044c\u043c\u0435\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<pre class=\"kotlin-code\" style=\"visibility: hidden; padding: 36px 0;\" data-highlight-only=\"true\">fun loadConfiguration() {\nGlobalScope.launch {\nval config = fetchConfigFromServer() \/\/ network request\nupdateConfiguration(config)\n}\n}\n<\/pre>\n<p>\u0412\u044b\u0437\u043e\u0432 <code>loadConfiguration<\/code> \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443 \u0432 <code>GlobalScope<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u0444\u043e\u043d\u043e\u0432\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435, \u0438 \u043d\u0435 \u0437\u0430\u0434\u0430\u043d\u044b \u043d\u0438\u043a\u0430\u043a\u0438\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0435\u0435 \u043e\u0442\u043c\u0435\u043d\u044b \u0438\u043b\u0438 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u0435\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f. \u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043d\u0430\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u0441\u0435\u0442\u0438 \u043d\u0438\u0437\u043a\u0430\u044f, \u043e\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u0432 \u0444\u043e\u043d\u043e\u0432\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435, \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u044b. \u041f\u0440\u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u0430\u0445 <code>loadConfiguration<\/code> \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0440\u0430\u0441\u0442\u0438.<\/p>\n<h2>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u0430\u044f \u0437\u0430\u043c\u0435\u043d\u0430<\/h2>\n<p>\u0412\u043e \u043c\u043d\u043e\u0433\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <code>GlobalScope<\/code> \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0437\u0431\u0435\u0433\u0430\u0442\u044c, \u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0443\u044e \u0435\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u043a\u0430\u043a <code>suspend<\/code>, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre class=\"kotlin-code\" style=\"visibility: hidden; padding: 36px 0;\" data-highlight-only=\"true\">suspend fun loadConfiguration() {\n    val config = fetchConfigFromServer() \/\/ network request\n    updateConfiguration(config)\n}\n<\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 <code>GlobalScope.launch<\/code> \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439, \u0438\u0445 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0441\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>coroutineScope<\/code>:<\/p>\n<pre class=\"kotlin-code\" style=\"visibility: hidden; padding: 36px 0;\" data-highlight-only=\"true\">\/\/ concurrently load configuration and data\nsuspend fun loadConfigurationAndData() {\n    coroutineScope {\n        launch { loadConfiguration() }\n        launch { loadData() }\n    }\n}\n<\/pre>\n<p>\u041f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0438\u0437 \u043d\u0435\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0432 \u043a\u043e\u0434\u0435 \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u0432\u043c\u0435\u0441\u0442\u043e <code>GlobalScope<\/code> \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 <code>CoroutineScope<\/code>.<\/p>\n<h2>\u0421\u043b\u0443\u0447\u0430\u0438 \u043e\u043f\u0440\u0430\u0432\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/h2>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0440\u044f\u0434 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0439, \u043a\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>GlobalScope<\/code> \u043e\u043f\u0440\u0430\u0432\u0434\u0430\u043d\u043d\u043e \u0438 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0444\u043e\u043d\u043e\u0432\u044b\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0433\u043e \u0441\u0440\u043e\u043a\u0430 \u0436\u0438\u0437\u043d\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u044d\u0442\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438, \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <code>GlobalScope<\/code> \u0435\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u044f\u0432\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e <code>@OptIn(DelicateCoroutinesApi::class)<\/code> \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0438\u0436\u0435:<\/p>\n<pre class=\"kotlin-code\" style=\"visibility: hidden; padding: 36px 0;\" data-highlight-only=\"true\">\/\/ A global coroutine to log statistics every second,\n\/\/ must be always active\n@OptIn(DelicateCoroutinesApi::class)\nval globalScopeReporter = GlobalScope.launch {\n    while (true) {\n        delay(1000)\n        logStatistics()\n    }\n}\n<\/pre>\n<p>\u041c\u044b \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u043c \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0441\u043b\u0443\u0447\u0430\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <code>GlobalScope<\/code> \u0438 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u0438\u0437 \u043d\u0438\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442 \u0432 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044e \u043e\u043f\u0440\u0430\u0432\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f. \u0412\u043e \u0432\u0441\u0435\u0445 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043e\u0448\u0438\u0431\u043a\u0430\u043c \u0432 \u043a\u043e\u0434\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c <code>GlobalScope<\/code>, \u043a\u0430\u043a \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0432\u044b\u0448\u0435.<\/p>\n<h1 id=\"junit\">\u0420\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0434\u043b\u044f JUnit 5<\/h1>\n<p>\u0412 \u043d\u043e\u0432\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e <code>CoroutinesTimeout<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0442\u0435\u0441\u0442\u044b \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435, \u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0438\u0445 \u043f\u043e\u0441\u043b\u0435 \u0438\u0441\u0442\u0435\u0447\u0435\u043d\u0438\u044f \u043e\u0442\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u0442\u043e\u043a. <code>CoroutinesTimeout<\/code> \u0443\u0436\u0435 \u0431\u044b\u043b \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0434\u043b\u044f JUnit 4. \u0412 \u044d\u0442\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044e \u0441 JUnit 5.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u0443\u044e \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e, \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u043e\u0432\u0443\u044e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c:<\/p>\n<pre class=\"kotlin-code\" style=\"visibility: hidden; padding: 36px 0;\" data-highlight-only=\"true\">dependencies {\n  \u2026\n  testImplementation(\"org.jetbrains.kotlinx:kotlinx-coroutines-debug:$coroutinesVersion\")\n}\n<\/pre>\n<p>\u0412\u043e\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e <code>CoroutinesTimeout<\/code> \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre class=\"kotlin-code\" style=\"visibility: hidden; padding: 36px 0;\" data-highlight-only=\"true\">import kotlinx.coroutines.debug.junit5.CoroutinesTimeout\nimport kotlinx.coroutines.delay\nimport kotlinx.coroutines.runBlocking\nimport org.junit.Test\n\n@CoroutinesTimeout(100)\nclass CoroutinesTimeoutSimpleTest {\n\n     @CoroutinesTimeout(300)\n     @Test\n     fun firstTest() {\n         runBlocking {\n             delay(200)  \/\/ succeeds\n         }\n     }\n\n     @Test\n     fun secondTest() {\n         runBlocking {\n             delay(200)  \/\/ fails\n         }\n     }\n }\n<\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0442\u0430\u0439\u043c-\u0430\u0443\u0442 \u043a\u043e\u0440\u0443\u0442\u0438\u043d \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043a\u043b\u0430\u0441\u0441\u0430, \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u0434\u043b\u044f <code>firstTest<\/code>. \u0414\u043b\u044f \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430 \u0442\u0430\u0439\u043c-\u0430\u0443\u0442 \u043d\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043a\u043b\u0430\u0441\u0441\u0430. <code>secondTest<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043a\u043b\u0430\u0441\u0441\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043d \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u0440\u0435\u0432\u044b\u0448\u0435\u043d\u0438\u0438 \u043b\u0438\u043c\u0438\u0442\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u0438.<\/p>\n<p>\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre class=\"kotlin-code\" style=\"visibility: hidden; padding: 36px 0;\" data-highlight-only=\"true\">package kotlinx.coroutines.debug.junit5\n\npublic annotation class CoroutinesTimeout(\n    val testTimeoutMs: Long,\n    val cancelOnTimeout: Boolean = false\n)\n<\/pre>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440, <code>testTimeoutMs<\/code>, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u0432 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445. \u0412\u0442\u043e\u0440\u043e\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440, <code>cancelOnTimeout<\/code>, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442, \u043d\u0443\u0436\u043d\u043e \u043b\u0438 \u043e\u0442\u043c\u0435\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u043f\u043e \u0438\u0441\u0442\u0435\u0447\u0435\u043d\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u0415\u0441\u043b\u0438 \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u0437\u0430\u0434\u0430\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>true<\/code>, \u0432\u0441\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0431\u0443\u0434\u0443\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0442\u043c\u0435\u043d\u0435\u043d\u044b.<\/p>\n<p>\u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <code>CoroutinesTimeout<\/code> \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f <a href=\"https:\/\/blog.jetbrains.com\/kotlin\/2020\/07\/kotlin-1-4-rc-debugging-coroutines\/\">\u043e\u0442\u043b\u0430\u0434\u0447\u0438\u043a \u043a\u043e\u0440\u0443\u0442\u0438\u043d<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0435\u043b\u0430\u0435\u0442 \u0434\u0430\u043c\u043f \u0432\u0441\u0435\u0445 \u043a\u043e\u0440\u0443\u0442\u0438\u043d \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0430. \u0414\u0430\u043c\u043f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0438 \u0441\u0442\u0435\u043a\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043e\u0440\u0443\u0442\u0438\u043d. \u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u043d\u0438\u0442\u044c \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0443 \u0441\u0442\u0435\u043a\u0430, \u0447\u0442\u043e\u0431\u044b \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e <code><a class=\"ek-link\" href=\"https:\/\/github.com\/Kotlin\/kotlinx.coroutines\/blob\/master\/kotlinx-coroutines-debug\/src\/junit\/junit5\/CoroutinesTimeoutExtension.kt\" target=\"_blank\" rel=\"noopener\">CoroutinesTimeoutExtension<\/a><\/code>\u00a0\u2014 \u044d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438.<\/p>\n<p>\u041c\u044b \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u0438\u043c <a href=\"https:\/\/github.com\/asarkar\" target=\"_blank\" rel=\"noopener\">\u0410\u0431\u0445\u0438\u0434\u0436\u0438\u0442\u0430 \u0421\u0430\u0440\u043a\u0430\u0440\u0430<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u043b \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u0431\u0440\u0430\u0437\u0435\u0446 <a class=\"ek-link\" href=\"https:\/\/github.com\/Kotlin\/kotlinx.coroutines\/issues\/2197\" target=\"_blank\" rel=\"noopener\">CoroutinesTimeout \u0434\u043b\u044f JUnit 5<\/a>. \u0418\u0434\u0435\u044f \u0431\u044b\u043b\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u0432 \u043d\u043e\u0432\u043e\u0439 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <code>CoroutinesTimeout<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u0432 \u0432\u0435\u0440\u0441\u0438\u044e 1.5.<\/p>\n<h1 id=\"channels\">\u0423\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f Channels API<\/h1>\n<p>\u041a\u0430\u043d\u0430\u043b\u044b \u2014 \u0432\u0430\u0436\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b \u043a\u043e\u043c\u043c\u0443\u043d\u0438\u043a\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c \u043e\u0431\u043c\u0435\u043d\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u043c\u0438. \u0412 \u044d\u0442\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u043c\u044b \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u043b\u0438 Channels API, \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u0432 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u044b\u0435 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u044b \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 <code>offer<\/code> \u0438 <code>poll<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0447\u0430\u0441\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438. \u0417\u0430\u043e\u0434\u043d\u043e \u043c\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u043d\u043e\u0432\u044b\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u0438 \u043d\u0435\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432.<\/p>\n<h2>\u041d\u043e\u0432\u044b\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u044f<\/h2>\n<p>\u041c\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0437\u0430\u0442\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u0445 \u0438\u043b\u0438 API \u043a\u043e\u0440\u0443\u0442\u0438\u043d. \u041d\u0430\u043c \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c, \u0447\u0442\u043e\u0431\u044b \u0438\u043c\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0435\u0441\u043b\u043e \u0432 \u0441\u0435\u0431\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0435\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0438. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0432\u043e\u0442 \u0447\u0442\u043e:<\/p>\n<ul>\n<li>\u0438\u043c\u0435\u043d\u0430 \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u0431\u0435\u0437 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439\u00a0\u2014 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>send<\/code>, <code>receive<\/code>;<\/li>\n<li>\u0432\u0441\u0435 \u0438\u043c\u0435\u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043d\u0435\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0441 \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u044f\u0446\u0438\u0435\u0439 \u043e\u0448\u0438\u0431\u043e\u043a \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442 \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u00abtry\u00bb: <code>trySend<\/code> \u0438 <code>tryReceive<\/code> \u0432\u043c\u0435\u0441\u0442\u043e \u043f\u0440\u0435\u0436\u043d\u0438\u0445 <code>offer<\/code> \u0438 <code>poll<\/code>;<\/li>\n<li>\u0438\u043c\u0435\u043d\u0430 \u043d\u043e\u0432\u044b\u0445 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0441 \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u044f\u0446\u0438\u0435\u0439 \u043e\u0448\u0438\u0431\u043e\u043a \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442 \u0441\u0443\u0444\u0444\u0438\u043a\u0441 \u00abCatching\u00bb.<\/li>\n<\/ul>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u0441 \u043d\u043e\u0432\u044b\u043c\u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435.<\/p>\n<h2>\u0424\u0443\u043d\u043a\u0446\u0438\u0438 <code>Try<\/code>: \u043d\u0435\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c\u044b\u0435 \u0430\u043d\u0430\u043b\u043e\u0433\u0438 \u0434\u043b\u044f <code>send<\/code> \u0438 <code>receive<\/code><\/h2>\n<p>\u041e\u0434\u043d\u0430 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0432 \u043a\u0430\u043d\u0430\u043b, \u0430 \u0434\u0440\u0443\u0433\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u0435\u0435 \u043e\u0442\u0442\u0443\u0434\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c. \u041e\u0431\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>send<\/code> \u0438 <code>receive<\/code>\u00a0\u2014 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c\u044b\u0435. <code>send<\/code> \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443, \u0435\u0441\u043b\u0438 \u043a\u0430\u043d\u0430\u043b \u043f\u043e\u043b\u043e\u043d \u0438 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043d\u044f\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u0430 <code>receive<\/code> \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0441\u0432\u043e\u044e \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443, \u0435\u0441\u043b\u0438 \u0432 \u043a\u0430\u043d\u0430\u043b\u0435 \u043d\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432:<\/p>\n<pre class=\"kotlin-code\" style=\"visibility: hidden; padding: 36px 0;\">import kotlinx.coroutines.channels.Channel\nimport kotlinx.coroutines.launch\nimport kotlinx.coroutines.runBlocking\n\nfun main() = runBlocking&lt;Unit&gt; {\n    val channel = Channel&lt;String&gt;()\n    launch {\n        \/\/ Suspends until the element can be sent\n        println(\"Sending...\")\n        channel.send(\"Element\")\n     }\n     \/\/ Suspends until the element can be received\n     println(\"Receiving...\")\n     println(channel.receive())\n}\n<\/pre>\n<p>\u0423 \u044d\u0442\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0435\u0441\u0442\u044c \u043d\u0435\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c\u044b\u0435 \u0430\u043d\u0430\u043b\u043e\u0433\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0432 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u043c \u043a\u043e\u0434\u0435: <code>offer<\/code> \u0438 <code>poll<\/code>. \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u043c\u0435\u0441\u0442\u043e \u043d\u0438\u0445 \u043f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c <code>trySend<\/code> \u0438 <code>tryReceive<\/code>, \u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u043f\u0440\u0435\u0436\u043d\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043f\u0440\u0435\u043a\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f. \u041d\u0438\u0436\u0435 \u043c\u044b \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0435\u043c \u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0430\u0445 \u0442\u0430\u043a\u0438\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439.<\/p>\n<p><code>offer<\/code> \u0438 <code>poll<\/code> \u0434\u043e\u043b\u0436\u043d\u044b \u0434\u0435\u043b\u0430\u0442\u044c \u0442\u043e \u0436\u0435, \u0447\u0442\u043e \u0438 <code>send<\/code> \u0438 <code>receive<\/code>, \u043d\u043e \u0431\u0435\u0437 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438. \u0417\u0432\u0443\u0447\u0438\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u0438 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043a\u043e\u0433\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0438\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442. \u0410 \u0432\u043e\u0442 \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043e\u0448\u0438\u0431\u043a\u0430, \u0432\u0441\u0435 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442\u0441\u044f. <code>send<\/code> \u0438 <code>receive<\/code> \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043d\u0435 \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443. <code>offer<\/code> \u0438 <code>poll<\/code> \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>false<\/code> \u0438 <code>null<\/code> \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0435\u0441\u043b\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043d\u0435\u043b\u044c\u0437\u044f \u0431\u044b\u043b\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u043a\u0430\u043d\u0430\u043b \u043f\u043e\u043b\u043e\u043d, \u0438\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u043a\u0430\u043d\u0430\u043b \u043f\u0443\u0441\u0442. \u041e\u0431\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u044b\u0434\u0430\u0432\u0430\u043b\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f, \u043f\u044b\u0442\u0430\u044f\u0441\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u043c \u043a\u0430\u043d\u0430\u043b\u043e\u043c, \u0438 \u0432\u043e\u0442 \u044d\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u043b\u043e \u0437\u0430\u0442\u0440\u0443\u0434\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u0438 \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438.<\/p>\n<pre class=\"kotlin-code\" style=\"visibility: hidden; padding: 36px 0;\">import kotlinx.coroutines.channels.Channel\nimport kotlinx.coroutines.launch\nimport kotlinx.coroutines.runBlocking\n\nfun main() = runBlocking&lt;Unit&gt; {\n    val channel = Channel&lt;String&gt;()\n    launch {\n        println(\"Sending...\")\n        \/\/ Doesn't suspend\n        \/\/ Returns 'false' if the channel is full\n        \/\/ Or throws an exception if it's closed\n        channel.offer(\"Element\")\n    }\n    println(\"Receiving...\")\n    \/\/ Doesn't suspend\n    \/\/ Returns 'null' if the channel is empty\n    println(channel.poll())\n\/\/  channel.close()\n}\n<\/pre>\n<p>\u0412 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>poll<\/code> \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0434\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043a\u0430\u043d\u0430\u043b \u0438 \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>null<\/code>. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043e\u043d\u0430 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u043d\u043e \u043c\u044b \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0435\u0435 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e. \u0412\u044b\u0437\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>offer<\/code> \u0442\u0430\u043a\u0436\u0435 \u043d\u0435 \u0443\u0434\u0430\u0435\u0442\u0441\u044f, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044d\u0442\u043e \u0440\u0430\u043d\u0434\u0435\u0432\u0443-\u043a\u0430\u043d\u0430\u043b \u0441 \u043d\u0443\u043b\u0435\u0432\u044b\u043c \u043e\u0431\u044a\u0435\u043c\u043e\u043c \u0431\u0443\u0444\u0435\u0440\u0430. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>offer<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>false<\/code>, \u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>poll<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>null<\/code>, \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d\u0438 \u0431\u044b\u043b\u0438 \u0432\u044b\u0437\u0432\u0430\u043d\u044b \u043d\u0435 \u0432 \u0442\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443 \u0441 \u0432\u044b\u0437\u043e\u0432\u043e\u043c <code>channel.close()<\/code>, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435. \u0422\u043e\u0433\u0434\u0430 <code>poll<\/code>, \u043a\u0430\u043a \u0438 \u0440\u0430\u043d\u044c\u0448\u0435, \u0432\u0435\u0440\u043d\u0435\u0442 <code>false<\/code>. \u041e\u0434\u043d\u0430\u043a\u043e \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e <code>offer<\/code> \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u0443\u0436\u0435 \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0439 \u043a\u0430\u043d\u0430\u043b \u0438 \u0432\u044b\u0434\u0430\u0441\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435. \u041c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u043b\u0438 \u043c\u043d\u043e\u0433\u043e \u0436\u0430\u043b\u043e\u0431 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0447\u0440\u0435\u0432\u0430\u0442\u043e \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438. \u041e\u0447\u0435\u043d\u044c \u043b\u0435\u0433\u043a\u043e \u0437\u0430\u0431\u044b\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u044d\u0442\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0430 \u0435\u0441\u043b\u0438 \u0435\u0433\u043e \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u043b\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0438\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u044d\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u043a \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b.<\/p>\n<p>\u041d\u043e\u0432\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>trySend<\/code> \u0438 <code>tryReceive<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b\u0438 \u0443\u0441\u0442\u0440\u0430\u043d\u0438\u0442\u044c \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u043e\u043d\u0438 \u0432\u044b\u0434\u0430\u044e\u0442 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442. \u041a\u0430\u0436\u0434\u0430\u044f \u0438\u0437 \u043d\u0438\u0445 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 <code>ChannelResult<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043e\u0434\u043d\u043e \u0438\u0437 \u0442\u0440\u0435\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439: \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435, \u0441\u0431\u043e\u0439 \u0438\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043a\u0430\u043d\u0430\u043b \u0431\u044b\u043b \u0437\u0430\u043a\u0440\u044b\u0442.<\/p>\n<pre class=\"kotlin-code\" style=\"visibility: hidden; padding: 36px 0;\">import kotlinx.coroutines.channels.Channel\nimport kotlinx.coroutines.launch\nimport kotlinx.coroutines.runBlocking\n\nfun main() = runBlocking&lt;Unit&gt; {\n    val channel = Channel&lt;String&gt;()\n    launch {\n        println(\"Sending...\")\n        \/\/ Doesn't suspend\n        \/\/ Returns 'Failed' if the channel is full\n        \/\/ Or 'Channel was closed' result if it's closed\n        val result = channel.trySend(\"Element\")\n        println(result)\n\n        \/\/We can verify the result\n        if(result.isClosed){\n            println(\"Sending failed. The channel is closed.\")\n        }\n    }\n    println(\"Receiving...\")\n    println(channel.tryReceive())\n\/\/  channel.close()\n}\n<\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439, \u043d\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>tryReceive<\/code> \u0438 <code>trySend<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442. \u0412\u043c\u0435\u0441\u0442\u043e <code>false<\/code> \u0438 <code>null<\/code> \u0432\u044b \u0432\u0438\u0434\u0438\u0442\u0435 \u0437\u0434\u0435\u0441\u044c <code>Value(Failed)<\/code>. \u041c\u043e\u0436\u043d\u043e \u0441\u043d\u043e\u0432\u0430 \u0443\u0431\u0440\u0430\u0442\u044c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u0441\u043e \u0441\u0442\u0440\u043e\u043a\u0438, \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u044e\u0449\u0435\u0439 \u043a\u0430\u043d\u0430\u043b, \u0438 \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e <code>trySend<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 <code>Closed<\/code>, \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435.<\/p>\n<p>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f <a href=\"https:\/\/kotlinlang.org\/docs\/inline-classes.html\" target=\"_blank\" rel=\"noopener\">inline-\u043a\u043b\u0430\u0441\u0441\u0430\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/a> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>ChannelResult<\/code> \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043d\u0438\u0436\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043e\u0431\u0435\u0440\u0442\u043e\u043a, \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0431\u0435\u0437 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0438 \u043b\u0438\u0448\u043d\u0435\u0439 \u0442\u0440\u0430\u0442\u044b \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432.<\/p>\n<h2>\u041f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u044e\u0449\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438: \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441 \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u044f\u0446\u0438\u0435\u0439 \u043e\u0448\u0438\u0431\u043e\u043a<\/h2>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u044d\u0442\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438, \u0438\u043c\u0435\u043d\u0430 \u043d\u043e\u0432\u044b\u0445 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0441 \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u044f\u0446\u0438\u0435\u0439 \u043e\u0448\u0438\u0431\u043e\u043a \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442 \u0441\u0443\u0444\u0444\u0438\u043a\u0441 \u00abCatching\u00bb. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u043e\u0432\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>receiveCatching<\/code> \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0435\u0441\u043b\u0438 \u043a\u0430\u043d\u0430\u043b \u0437\u0430\u043a\u0440\u044b\u0442. \u0412\u043e\u0437\u044c\u043c\u0435\u043c \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre class=\"kotlin-code\" style=\"visibility: hidden; padding: 36px 0;\">import kotlinx.coroutines.channels.Channel\nimport kotlinx.coroutines.launch\nimport kotlinx.coroutines.runBlocking\n\nfun main() = runBlocking&lt;Unit&gt; {\n    val channel = Channel&lt;String&gt;()\n    channel.close()\n    println(channel.receiveCatching())\n}\n<\/pre>\n<p>\u041a\u0430\u043d\u0430\u043b \u0431\u044b\u043b \u0437\u0430\u043a\u0440\u044b\u0442, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043c\u044b \u043f\u043e\u043f\u044b\u0442\u0430\u043b\u0438\u0441\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u041e\u0434\u043d\u0430\u043a\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435\u043c, \u0447\u0442\u043e \u043a\u0430\u043d\u0430\u043b \u0431\u044b\u043b \u0437\u0430\u043a\u0440\u044b\u0442. \u0415\u0441\u043b\u0438 \u0432\u043c\u0435\u0441\u0442\u043e <code>receiveCatching<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>receive<\/code>, \u043e\u043d\u0430 \u0432\u044b\u0434\u0430\u0441\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 <code>ClosedReceiveChannelException<\/code>:<\/p>\n<pre class=\"kotlin-code\" style=\"visibility: hidden; padding: 36px 0;\">import kotlinx.coroutines.channels.Channel\nimport kotlinx.coroutines.launch\nimport kotlinx.coroutines.runBlocking\n\nfun main() = runBlocking&lt;Unit&gt; {\n    val channel = Channel&lt;String&gt;()\n    channel.close()\n    println(channel.receive())\n}\n<\/pre>\n<p>\u041f\u043e\u043a\u0430 \u0447\u0442\u043e \u043c\u044b \u0432\u0432\u0435\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>receiveCatching<\/code> \u0438 <code>onReceiveCatching<\/code> (\u0432\u043c\u0435\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0432\u0448\u0435\u0439\u0441\u044f \u0440\u0430\u043d\u0435\u0435 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>receiveOrClosed<\/code>), \u043d\u043e \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u043e\u0432\u044b\u0435.<\/p>\n<h2>\u041f\u0435\u0440\u0435\u0445\u043e\u0434 \u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u043d\u043e\u0432\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432 \u043a\u043e\u0434\u0435<\/h2>\n<p>\u0412\u043e \u0432\u0441\u0435\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445, \u0433\u0434\u0435 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>offer<\/code> \u0438 <code>poll<\/code>, \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u043e\u0432\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 <code>offer<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b\u0430 <code>Boolean<\/code>, \u0435\u0435 \u0440\u0430\u0432\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0439 \u0437\u0430\u043c\u0435\u043d\u043e\u0439 \u0441\u0442\u0430\u043d\u0435\u0442 <code>channel.trySend(\"\u042d\u043b\u0435\u043c\u0435\u043d\u0442\").isSuccess<\/code>.<\/p>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-142625\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2021\/05\/cor15-offer-deprecated.png\" alt=\"\" width=\"1600\" height=\"800\" \/><\/figure>\n<p>\u0412 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c <code>poll<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u044e\u0449\u0438\u0439 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 null, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0435 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442 <code>channel.tryReceive().getOrNull()<\/code>.<\/p>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-142636\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2021\/05\/cor15-poll-deprecated.png\" alt=\"\" width=\"1440\" height=\"440\" \/><\/figure>\n<p>\u0415\u0441\u043b\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0437\u043e\u0432\u0430 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d, \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u043d\u044f\u0442\u044c \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u043e\u0432\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f, \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u044b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043d\u0443\u0436\u043d\u043e \u0432\u043d\u0435\u0441\u0442\u0438 \u0432\u0440\u0443\u0447\u043d\u0443\u044e. \u0415\u0441\u043b\u0438 \u043a\u043e\u0434 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043c\u0435\u0442\u043e\u0434\u044b \u00aboffer\u00bb \u0438 \u00abpoll\u00bb \u0432\u044b\u0434\u0430\u044e\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u043e\u043c \u043a\u0430\u043d\u0430\u043b\u0435, \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u0430\u043c\u0435\u043d\u044b.<\/p>\n<p>\u0420\u0430\u0432\u043d\u043e\u0446\u0435\u043d\u043d\u0430\u044f \u0437\u0430\u043c\u0435\u043d\u0430 \u0434\u043b\u044f <code>channel.offer(\"\u042d\u043b\u0435\u043c\u0435\u043d\u0442\")<\/code> \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u044b\u0434\u0430\u0432\u0430\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0435\u0441\u043b\u0438 \u043a\u0430\u043d\u0430\u043b \u0437\u0430\u043a\u0440\u044b\u0442, \u0434\u0430\u0436\u0435 \u043f\u0440\u0438 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u043c \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0438:<\/p>\n<pre class=\"kotlin-code\" style=\"visibility: hidden; padding: 36px 0;\" data-highlight-only=\"true\">channel\n  .trySend(\"Element\")\n  .onClosed { throw it ?: ClosedSendChannelException(\"Channel was closed\") }\n  .isSuccess\n<\/pre>\n<p>\u0420\u0430\u0432\u043d\u043e\u0446\u0435\u043d\u043d\u0430\u044f \u0437\u0430\u043c\u0435\u043d\u0430 \u0434\u043b\u044f <code>channel.poll()<\/code> \u0432\u044b\u0434\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0435\u0441\u043b\u0438 \u043a\u0430\u043d\u0430\u043b \u0437\u0430\u043a\u0440\u044b\u0442 \u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439, \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>null<\/code>, \u0435\u0441\u043b\u0438 \u043e\u043d \u0431\u044b\u043b \u0437\u0430\u043a\u0440\u044b\u0442 \u0432 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435:<\/p>\n<pre class=\"kotlin-code\" style=\"visibility: hidden; padding: 36px 0;\" data-highlight-only=\"true\">channel.tryReceive()\n  .onClosed { if (it != null) throw it }\n  .getOrNull()\n<\/pre>\n<p>\u0422\u0430\u043a\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0439 <code>offer<\/code> \u0438 <code>poll<\/code>.<\/p>\n<p>\u041c\u044b \u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c, \u0447\u0442\u043e \u043e\u0431\u044b\u0447\u043d\u043e \u043a\u043e\u0434 \u043d\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u0442\u0430\u043a\u0438\u0435 \u0442\u043e\u043d\u043a\u0438\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f \u0432 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0438 \u043f\u0440\u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u043e\u043c \u043a\u0430\u043d\u0430\u043b\u0435, \u0438 \u043e\u043d\u0438 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043b\u0438 \u043a \u043e\u0448\u0438\u0431\u043a\u0430\u043c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0437\u0430\u043c\u0435\u043d\u0430 \u0432 IDE \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0443 \u043a\u043e\u0434\u0430. \u0415\u0441\u043b\u0438 \u0432 \u0432\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a, \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u044d\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0438 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u043a\u043e\u0434 \u0432\u0440\u0443\u0447\u043d\u0443\u044e. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0441\u0442\u043e\u0438\u0442 \u0435\u0433\u043e \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u0441 \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u043c \u043a\u0430\u043d\u0430\u043b\u043e\u043c \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043b\u0438\u0441\u044c \u0438\u043d\u0430\u0447\u0435, \u0431\u0435\u0437 \u0432\u044b\u0437\u043e\u0432\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439.<\/p>\n<h1 id=\"reactive\">\u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0441 \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c\u0438 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438\u00a0\u2014 \u043f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0431\u0438\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h1>\n<p>\u0412 \u0432\u0435\u0440\u0441\u0438\u0438 1.5 \u0441\u0442\u0430\u0442\u0443\u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u0445 \u0437\u0430 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044e \u0441 \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c\u0438 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430\u043c\u0438, \u0431\u044b\u043b \u043f\u043e\u0432\u044b\u0448\u0435\u043d \u0434\u043e \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0433\u043e API.<\/p>\n<p>\u0412 \u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u0435 JVM \u0435\u0441\u0442\u044c \u0440\u044f\u0434 \u0444\u0440\u0435\u043c\u0432\u043e\u0440\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043e\u043c <a href=\"https:\/\/www.reactive-streams.org\/\" target=\"_blank\" rel=\"noopener\">\u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432<\/a>. \u0414\u0432\u0430 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 Java, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044d\u0442\u043e \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e\u0442,\u00a0\u2014 <a href=\"https:\/\/projectreactor.io\/\" target=\"_blank\" rel=\"noopener\">Project Reactor<\/a> \u0438 <a href=\"https:\/\/github.com\/ReactiveX\/RxJava\" target=\"_blank\" rel=\"noopener\">RxJava<\/a>.<\/p>\n<p>\u041f\u043e\u0442\u043e\u043a\u0438 <a href=\"https:\/\/kotlinlang.org\/docs\/flow.html\" target=\"_blank\" rel=\"noopener\">Kotlin Flows<\/a> \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0438\u043d\u0430\u0447\u0435, \u0438 \u0438\u0445 \u0442\u0438\u043f\u044b \u043d\u0435\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b \u0441 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u043c\u0438 \u0432 \u044d\u0442\u043e\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0435, \u043d\u043e \u043f\u043e \u0441\u0432\u043e\u0435\u0439 \u0441\u0443\u0442\u0438 \u044d\u0442\u043e \u0442\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u043f\u043e\u0442\u043e\u043a\u0438. \u041f\u043e\u0442\u043e\u043a <code>Flow<\/code> \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a <code>Publisher<\/code> (\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u0439 \u0441\u043e \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0435\u0439 \u0438 <a href=\"https:\/\/github.com\/reactive-streams\/reactive-streams-jvm\/tree\/master\/tck\" target=\"_blank\" rel=\"noopener\">TCK<\/a>) \u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442. <code>kotlinx.coroutines<\/code> \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u044f\u0445.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c \u0441 \u0442\u0438\u043f\u0430\u043c\u0438 Project Reactor, \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438:<\/p>\n<pre class=\"kotlin-code\" style=\"visibility: hidden; padding: 36px 0;\" data-highlight-only=\"true\">dependencies {\n    implementation(\"org.jetbrains.kotlinx:kotlinx-coroutines-core:${coroutinesVersion}\")\n    implementation(\"org.jetbrains.kotlinx:kotlinx-coroutines-reactor:${coroutinesVersion}\")\n}\n<\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>Flow&lt;T&gt;.asPublisher()<\/code>, \u0435\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0438\u043f\u044b <em>Reactive Streams<\/em>, \u0438\u043b\u0438 <code>Flow&lt;T&gt;.asFlux()<\/code>, \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0438\u043f\u044b Project Reactor.<\/p>\n<pre class=\"kotlin-code\" style=\"visibility: hidden; padding: 36px 0;\" data-highlight-only=\"true\">\/\/ acquire a Flow instance\nval flow: Flow&lt;event&gt; = flow { \u2026 }\n\n\/\/ Convert Flow to Publisher\nval publisher = flow.asPublisher()\n\n\/\/ Convert Flow to Reactor's Flux\nval flux = flow.asFlux()\n\n\/\/Convert back to Flow\nval anotherFlow = flux.asFlow()\n<\/pre>\n<p>\u042d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0441\u0436\u0430\u0442\u043e\u0435 \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u0430. \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u0430 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f, \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u043c <a href=\"https:\/\/elizarov.medium.com\/reactive-streams-and-kotlin-flows-bfd12772cda4\" target=\"_blank\" rel=\"noopener\">\u0441\u0442\u0430\u0442\u044c\u044e \u0420\u043e\u043c\u0430\u043d\u0430 \u0415\u043b\u0438\u0437\u0430\u0440\u043e\u0432\u0430 \u043e \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043f\u043e\u0442\u043e\u043a\u0430\u0445 \u0438 Kotlin Flows<\/a>.<\/p>\n<p>\u0425\u043e\u0442\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0441 \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u0442\u0430\u0431\u0438\u043b\u0438\u0437\u0430\u0446\u0438\u0438 API, \u0441 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 <code>@ExperimentalCoroutinesApi<\/code> \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0441\u0442\u0430\u0432\u0448\u0438\u0435\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e \u0440\u0430\u0437\u043d\u044b\u043c \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f\u043c.<\/p>\n<h2>\u0423\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u0430\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0441 \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c\u0438 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438<\/h2>\n<p>\u0421\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c \u0441\u043e \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0435\u0439 \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0432\u0430\u0436\u043d\u0430 \u0434\u043b\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u0438\u043d\u0442\u0435\u0440\u043e\u043f\u0435\u0440\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043c\u0435\u0436\u0434\u0443 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u043c\u0438 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430\u043c\u0438 \u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0432 \u0441\u0442\u0430\u0440\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445, \u043d\u0435 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u044f \u0432\u0435\u0441\u044c \u043a\u043e\u0434.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u043c\u044b \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u043b\u0438 \u0441\u0442\u0430\u0442\u0443\u0441 \u00ab\u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u044b\u0439\u00bb <a href=\"https:\/\/github.com\/Kotlin\/kotlinx.coroutines\/commit\/47a063c0987177551bdbdf09a458998a30571ac2\" target=\"_blank\" rel=\"noopener\">\u0434\u043b\u0438\u043d\u043d\u043e\u043c\u0443 \u0441\u043f\u0438\u0441\u043a\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0439<\/a>. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u044b\u0439 \u0442\u0438\u043f \u0438\u0437 \u043b\u044e\u0431\u043e\u0433\u043e \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \u0432\u043e <code>Flow<\/code> \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u043e\u0432\u044b\u0439 \u043a\u043e\u0434 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Coroutines \u0438 \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u0441\u043e \u0441\u0442\u0430\u0440\u043e\u0439 \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u043a\u043e\u0434\u043e\u0432\u043e\u0439 \u0431\u0430\u0437\u043e\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u0441\u0442\u0440\u0435\u0447\u043d\u044b\u0445 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440\u043e\u0432:<\/p>\n<pre class=\"kotlin-code\" style=\"visibility: hidden; padding: 36px 0;\" data-highlight-only=\"true\">fun legacyFunThatHaveToReturnObservable(): Observable&lt;int&gt; {\n  return flow&lt;int&gt; {\n    \/\/ Use the power of flow!\n  }\n  \/\/ various flow operations\n  .asObservable()\n}\n<\/pre>\n<p>\u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0431\u044b\u043b\u043e \u0432\u043d\u0435\u0441\u0435\u043d\u043e \u043c\u043d\u043e\u0433\u043e <a href=\"https:\/\/github.com\/Kotlin\/kotlinx.coroutines\/pull\/2622\" target=\"_blank\" rel=\"noopener\">\u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0439<\/a> \u0432 <a href=\"https:\/\/github.com\/Kotlin\/kotlinx.coroutines\/blob\/master\/reactive\/kotlinx-coroutines-reactor\/src\/ReactorContext.kt\" target=\"_blank\" rel=\"noopener\"><code>ReactorContext<\/code><\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u0442 <a href=\"https:\/\/projectreactor.io\/docs\/core\/release\/reference\/#context\" target=\"_blank\" rel=\"noopener\">\u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442<\/a> Reactor \u0432 <a href=\"https:\/\/kotlinlang.org\/docs\/coroutine-context-and-dispatchers.html\" target=\"_blank\" rel=\"noopener\">CoroutineContext<\/a>, \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044f \u043f\u043e\u043b\u043d\u0443\u044e \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044e \u043c\u0435\u0436\u0434\u0443 Project Reactor \u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438 \u0432 Kotlin. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0435\u0439 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u044f\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 Reactor \u0432 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u0445.<\/p>\n<p>\u041a\u043e\u043d\u0442\u0435\u0441\u0442 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u044f\u0432\u043d\u043e \u043a\u0430\u043a \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u043e\u0432 \u0432\u043e \u0432\u0441\u0435\u0445 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f\u0445 \u0441 \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c\u0438 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438\u00a0\u2014 <code>Mono<\/code>, <code>Flux<\/code>, <code>Publisher.asFlow<\/code>, <code>Flow.asPublisher<\/code> \u0438 <code>Flow.asFlux<\/code>. \u0412\u043e\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u044f <code>Context<\/code> \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u0430 \u0432 <code>ReactorContext<\/code>:<\/p>\n<pre class=\"kotlin-code\" style=\"visibility: hidden; padding: 36px 0;\" data-highlight-only=\"true\">import kotlinx.coroutines.currentCoroutineContext\nimport kotlinx.coroutines.flow.flow\nimport kotlinx.coroutines.reactor.ReactorContext\nimport kotlinx.coroutines.reactor.asFlux\n\nfun main() {\n    val flow = flow&lt;int&gt; {\n       println(\"Reactor context in Flow: \" +\n          currentCoroutineContext()[ReactorContext]?.context)\n    }\n\n    \/\/ No context\n    \/\/ prints \"Reactor context in Flow: null\"\n    flow.asFlux().subscribe()\n\n    \/\/ Add subscriber's context\n    \/\/ prints \"Reactor context in Flow: Context1{answer=42}\"\n    flow.asFlux()\n        .contextWrite { ctx -&gt; ctx.put(\"answer\", 42) }\n        .subscribe()\n}\n<\/pre>\n<p>\u0412 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 <code>Flow<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u0442\u0435\u043c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 Reactor Flux \u0431\u0435\u0437 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430. \u0412\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 <code>subscribe()<\/code> \u0431\u0435\u0437 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442 \u0443 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0443 <em>\u0432\u0441\u0435\u0445<\/em> \u0434\u0430\u043d\u043d\u044b\u0445. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0444\u0440\u0430\u0437\u0443 \u00ab<em>Reactor context in Flow: null<\/em>\u00bb.<\/p>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0446\u0435\u043f\u043e\u0447\u043a\u0430 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 <code>Flow<\/code> \u0432\u043e <code>Flux<\/code>, \u043d\u043e \u0437\u0430\u0442\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0430\u0440\u0443 \u043a\u043b\u044e\u0447-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, <em>answer=42<\/em>, \u043a \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0443 Reactor \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0446\u0435\u043f\u043e\u0447\u043a\u0438. \u0412\u044b\u0437\u043e\u0432 <code>subscribe()<\/code> \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0442\u0440\u0438\u0433\u0433\u0435\u0440\u043e\u043c \u0434\u043b\u044f \u0432\u0441\u0435\u0439 \u0446\u0435\u043f\u043e\u0447\u043a\u0438. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d, \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0444\u0440\u0430\u0437\u0443 \u00ab<em>Reactor context in Flow: Context1{answer=42}<\/em>\u00bb<\/p>\n<h2>\u041d\u043e\u0432\u044b\u0435 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/h2>\n<p>\u041f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441 <code>Mono<\/code>, \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044f \u043f\u043e\u0442\u043e\u043a. \u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u044d\u0442\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438, \u043c\u044b <a href=\"https:\/\/github.com\/Kotlin\/kotlinx.coroutines\/pull\/2628\" target=\"_blank\" rel=\"noopener\">\u043f\u0440\u0435\u043a\u0440\u0430\u0442\u0438\u043b\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443<\/a> \u0444\u0443\u043d\u043a\u0446\u0438\u0439 <code>awaitSingleOr*<\/code> \u0434\u043b\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0445 <code>Publisher<\/code> \u0438 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>await*<\/code> \u0434\u043b\u044f <code>Mono<\/code> \u0438 <code>Maybe<\/code>.<\/p>\n<p><code>Mono<\/code> \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043d\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0442\u0430\u043a \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432\u0441\u0435\u0433\u0434\u0430 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u0435\u043d \u043f\u0435\u0440\u0432\u043e\u043c\u0443. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u043e\u0441\u0442\u0430\u0432\u0448\u0438\u0445\u0441\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0442\u043e\u0436\u0435 \u0431\u0435\u0441\u043f\u043e\u043b\u0435\u0437\u043d\u0430. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 <code>Mono.awaitFirst()<\/code> \u0438 <code>Mono.awaitLast()<\/code> \u043f\u0440\u0435\u043a\u0440\u0430\u0449\u0435\u043d\u0430, \u0432\u043c\u0435\u0441\u0442\u043e \u043d\u0438\u0445 \u0432\u0432\u043e\u0434\u0438\u0442\u0441\u044f <code>Mono.awaitSingle()<\/code>.<\/p>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-142647\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2021\/05\/cor15-reactive-streams-awaitFirst.png\" alt=\"\" width=\"1600\" height=\"906\" \/><\/figure>\n<h1 id=\"use-coroutines-1-5-0\">\u041d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 kotlinx.coroutines 1.5.0!<\/h1>\n<p>\u0412 \u043d\u043e\u0432\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u043f\u043e\u044f\u0432\u0438\u043b\u043e\u0441\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439. \u041d\u043e\u0432\u044b\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u044f, \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u0438 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0438 Channels API, \u0441\u0442\u0430\u043b\u0438 \u0434\u043b\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u0435\u043c. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043c\u044b \u0441\u0442\u0430\u0440\u0430\u0435\u043c\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c API \u043a\u043e\u0440\u0443\u0442\u0438\u043d \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u043c.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u0430\u0447\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u043d\u043e\u0432\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0435\u0439, \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0444\u0430\u0439\u043b\u0430 build.gradle.kts. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044c\u0442\u0435, \u0447\u0442\u043e \u0443 \u0432\u0430\u0441 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0430 \u0441\u0430\u043c\u0430\u044f \u0441\u0432\u0435\u0436\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f Kotlin \u043f\u043b\u0430\u0433\u0438\u043d\u0430 \u0432 Gradle:<\/p>\n<pre class=\"kotlin-code\" style=\"visibility: hidden; padding: 36px 0;\" data-highlight-only=\"true\">plugins {\n   kotlin(\"jvm\") version \"1.5.0\"\n}\n<\/pre>\n<p>\u0417\u0430\u0442\u0435\u043c \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u0435 \u0432\u0435\u0440\u0441\u0438\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 \u0441 \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c\u0438 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438.<\/p>\n<pre class=\"kotlin-code\" style=\"visibility: hidden; padding: 36px 0;\" data-highlight-only=\"true\">val coroutinesVersion = \"1.5.0\"\n\ndependencies {\n  implementation(\"org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:$coroutinesVersion\")\n  implementation(\"org.jetbrains.kotlinx:kotlinx-coroutines-reactive:$coroutinesVersion\")\n  implementation(\"org.jetbrains.kotlinx:kotlinx-coroutines-reactor:$coroutinesVersion\")\n  implementation(\"org.jetbrains.kotlinx:kotlinx-coroutines-rx3:$coroutinesVersion\")\n  ...\n}\n<\/pre>\n<h1>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b<\/h1>\n<ul>\n<li><a class=\"ek-link\" href=\"https:\/\/youtu.be\/EVLnWOcR0is\" target=\"_blank\" rel=\"noopener\">\u0412\u0438\u0434\u0435\u043e \u043f\u043e \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c 1.5.0<\/a><\/li>\n<li><a href=\"https:\/\/kotlinlang.org\/docs\/coroutines-guide.html\" target=\"_blank\" rel=\"noopener\">\u0420\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043f\u043e \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c<\/a><\/li>\n<li><a href=\"https:\/\/kotlin.github.io\/kotlinx.coroutines\/\" target=\"_blank\" rel=\"noopener\">\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043f\u043e API<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/Kotlin\/kotlinx.coroutines\" target=\"_blank\" rel=\"noopener\">\u0420\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 kotlinx.coroutines \u043d\u0430 GitHub<\/a><\/li>\n<li><a class=\"ek-link\" href=\"https:\/\/blog.jetbrains.com\/kotlin\/2020\/10\/kotlinx-coroutines-1-4-0-introducing-stateflow-and-sharedflow\/\">\u0421\u0442\u0430\u0442\u044c\u044f \u0432 \u0431\u043b\u043e\u0433\u0435 \u043e \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u0445 1.4.0<\/a><\/li>\n<li><a class=\"ek-link\" href=\"https:\/\/blog.jetbrains.com\/kotlin\/2021\/05\/kotlin-1-5-0-released\/\">\u0421\u0442\u0430\u0442\u044c\u044f \u0432 \u0431\u043b\u043e\u0433\u0435 \u043e Kotlin 1.5.0<\/a><\/li>\n<\/ul>\n<h3>\u0415\u0441\u043b\u0438 \u0432\u044b \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0438\u0441\u044c \u0441 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u043c\u0438<\/h3>\n<ul>\n<li>\u0421\u043e\u043e\u0431\u0449\u0430\u0439\u0442\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u0432 <a href=\"https:\/\/github.com\/Kotlin\/kotlinx.coroutines\/issues\" target=\"_blank\" rel=\"noopener\">\u0431\u0430\u0433-\u0442\u0440\u0435\u043a\u0435\u0440\u0435 GitHub<\/a>.<\/li>\n<li>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435\u0441\u044c \u0437\u0430 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432 \u043a\u0430\u043d\u0430\u043b\u0435 #coroutines \u0432 Kotlin Slack (<a href=\"https:\/\/surveys.jetbrains.com\/s3\/kotlin-slack-sign-up\" target=\"_blank\" rel=\"noopener\">\u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435\u0441\u044c \u043f\u0440\u0438\u0433\u043b\u0430\u0448\u0435\u043d\u0438\u0435\u043c<\/a>).<\/li>\n<\/ul>\n<p><em>\u0412\u0430\u0448\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 Kotlin<\/em><\/p>\n<p><em>The Drive to Develop<\/em><\/p>\n\n\n<p><\/p>\n","protected":false},"author":820,"featured_media":142998,"comment_status":"closed","ping_status":"closed","template":"","categories":[909],"tags":[],"cross-post-tag":[],"acf":[],"_links":{"self":[{"href":"https:\/\/blog.jetbrains.com\/ru\/wp-json\/wp\/v2\/kotlin\/150519"}],"collection":[{"href":"https:\/\/blog.jetbrains.com\/ru\/wp-json\/wp\/v2\/kotlin"}],"about":[{"href":"https:\/\/blog.jetbrains.com\/ru\/wp-json\/wp\/v2\/types\/kotlin"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/ru\/wp-json\/wp\/v2\/users\/820"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/ru\/wp-json\/wp\/v2\/comments?post=150519"}],"version-history":[{"count":9,"href":"https:\/\/blog.jetbrains.com\/ru\/wp-json\/wp\/v2\/kotlin\/150519\/revisions"}],"predecessor-version":[{"id":150646,"href":"https:\/\/blog.jetbrains.com\/ru\/wp-json\/wp\/v2\/kotlin\/150519\/revisions\/150646"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/ru\/wp-json\/wp\/v2\/media\/142998"}],"wp:attachment":[{"href":"https:\/\/blog.jetbrains.com\/ru\/wp-json\/wp\/v2\/media?parent=150519"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/ru\/wp-json\/wp\/v2\/categories?post=150519"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/ru\/wp-json\/wp\/v2\/tags?post=150519"},{"taxonomy":"cross-post-tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/ru\/wp-json\/wp\/v2\/cross-post-tag?post=150519"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}