{"id":288727,"date":"2018-08-30T13:20:02","date_gmt":"2018-08-30T09:20:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=288727"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=288727","title":{"rendered":"\u041a\u0430\u043a \u044f \u0437\u0430\u043c\u0435\u043d\u0438\u043b RxJava \u043d\u0430 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0432 \u0441\u0432\u043e\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0438 \u043f\u043e\u0447\u0435\u043c\u0443 \u0432\u0430\u043c \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0441\u0442\u043e\u0438\u0442 \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c"},"content":{"rendered":"\n<div data-io-article-url=\"https:\/\/habr.com\/post\/421739\/\" class=\"post__text post__text-html js-mediator-article\">\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u0432\u0430\u043c \u043f\u0435\u0440\u0435\u0432\u043e\u0434 <a href=\"https:\/\/proandroiddev.com\/i-exchanged-rxjava-for-coroutines-in-my-android-application-why-you-probably-should-do-the-same-5526dfb38d0e\">\u0441\u0442\u0430\u0442\u044c\u0438<\/a> \u0430\u0432\u0442\u043e\u0440\u0430 Paulo Sato \u043d\u0430 \u0442\u0435\u043c\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f Kotlin Coroutines \u0432\u043c\u0435\u0441\u0442\u043e RxJava \u0432 \u0441\u0432\u043e\u0438\u0445 Android \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445.<\/p>\n<p>  RxJava \u043a\u0430\u043a \u0431\u0430\u0437\u0443\u043a\u0430, \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0438 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u044b \u0435\u0451 \u043e\u0433\u043d\u0435\u0432\u043e\u0439 \u043c\u043e\u0449\u0438. \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u043e\u0439\u0434\u0435\u0442 \u0440\u0435\u0447\u044c \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0435\u0451 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438 (\u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u043c\u0438) Kotlin.<\/p>\n<p>  \u042f \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0441 RxJava \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043b\u0435\u0442. \u042d\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e \u043e\u0434\u043d\u0430 \u0438\u0437 \u043b\u0443\u0447\u0448\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e Android \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u0432 \u0443\u0434\u0430\u0440\u0435, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e, \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u0443\u0435\u0442\u0435 \u043d\u0430 Java. \u0415\u0441\u043b\u0438 \u0436\u0435 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 Kotlin, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0432 \u0433\u043e\u0440\u043e\u0434\u0435 \u043d\u043e\u0432\u044b\u0439 \u0448\u0435\u0440\u0438\u0444. <\/p>\n<p>  \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 RxJava \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0442\u043e\u043a\u0438 \u0438 \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f callback hell (\u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0437\u043d\u0430\u0435\u0442\u0435, \u0447\u0442\u043e \u044d\u0442\u043e \u0442\u0430\u043a\u043e\u0435, \u0441\u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u0441\u0435\u0431\u044f \u0441\u0447\u0430\u0441\u0442\u043b\u0438\u0432\u0447\u0438\u043a\u043e\u043c \u0438 <a href=\"https:\/\/www.quora.com\/What-is-callback-hell\">\u0432\u043e\u0442 \u043f\u043e\u0447\u0435\u043c\u0443<\/a>). \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u043c\u0435\u0442\u044c \u0432\u0432\u0438\u0434\u0443, \u0447\u0442\u043e \u0440\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u043c\u043e\u0449\u044c RxJava \u2014 \u044d\u0442\u043e \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 backpressure. \u0415\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u0435\u0451 \u0434\u043b\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u0431\u0430\u0437\u0443\u043a\u0443, \u0447\u0442\u043e\u0431\u044b \u0443\u0431\u0438\u0442\u044c \u043f\u0430\u0443\u043a\u0430. \u041e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0432\u043e\u044e \u0440\u0430\u0431\u043e\u0442\u0443, \u043d\u043e \u044d\u0442\u043e \u043f\u0435\u0440\u0435\u0431\u043e\u0440.<\/p>\n<p>  \u041e\u0434\u043d\u0438\u043c \u0437\u0430\u043c\u0435\u0442\u043d\u044b\u043c \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u043c RxJava \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u0432. \u041e\u043d\u043e \u043e\u0433\u0440\u043e\u043c\u043d\u043e \u0438 \u0438\u043c\u0435\u0435\u0442 \u0442\u0435\u043d\u0434\u0435\u043d\u0446\u0438\u044e \u0440\u0430\u0441\u043f\u043e\u043b\u0437\u0430\u0442\u044c\u0441\u044f \u043f\u043e \u0432\u0441\u0435\u043c\u0443 \u043a\u043e\u0434\u0443. \u0412 Kotlin \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u044b \u0440\u0430\u043d\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f RxJava. <\/p>\n<p>  \u041d\u043e\u2026 \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b?<\/p>\n<p>  \u041a\u043e\u0440\u0443\u0442\u0438\u043d \u2014 \u044d\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u0432 \u043f\u043e\u0442\u043e\u043a\u0435. \u041f\u043e\u0442\u043e\u043a \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043f\u043e\u043a\u0430 \u043d\u0435 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0431\u0443\u0434\u0435\u0442 \u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430 \u0431\u0435\u0437 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430.<br \/>  \u041a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0432 Kotlin \u0432\u0441\u0451 \u0435\u0449\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u044d\u043a\u0441\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u043c\u0438, \u043d\u043e \u043e\u043d\u0438 \u0432\u043e\u0448\u043b\u0438 \u0432 Kotlin 1.3, \u0442\u0430\u043a \u0447\u0442\u043e \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u043d\u0438\u0436\u0435 \u043d\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 UseCase (\u0434\u043b\u044f clean architecture), \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0439 \u0438\u0445. \u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u0432\u044b\u0437\u043e\u0432 \u043a\u043e\u0440\u0443\u0442\u0438\u043d \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d \u0432 \u043e\u0434\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u043b\u043e\u0438 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0445 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c, \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044f \u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0437\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u043d\u0443\u044e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<pre><code>\/**  * (C) Copyright 2018 Paulo Vitor Sato Open Source Project  *  * Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);  * you may not use this file except in compliance with the License.  * You may obtain a copy of the License at  *  *     http:\/\/www.apache.org\/licenses\/LICENSE-2.0  *  * Unless required by applicable law or agreed to in writing, software  * distributed under the License is distributed on an &quot;AS IS&quot; BASIS,  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  * See the License for the specific language governing permissions and  * limitations under the License.  *  *\/  package com.psato.devcamp.interactor.usecase  import android.util.Log import kotlinx.coroutines.experimental.* import kotlinx.coroutines.experimental.android.UI import kotlin.coroutines.experimental.CoroutineContext   \/**  * Abstract class for a Use Case (Interactor in terms of Clean Architecture).  * This interface represents a execution unit for different use cases (this means any use case  * in the application should implement this contract).  * &lt;p&gt;  * By convention each UseCase implementation will return the result using a coroutine  * that will execute its job in a background thread and will post the result in the UI thread.  *\/ abstract class UseCase&lt;T&gt; {      protected var parentJob: Job = Job()     \/\/var backgroundContext: CoroutineContext = IO     var backgroundContext: CoroutineContext = CommonPool     var foregroundContext: CoroutineContext = UI       protected abstract suspend fun executeOnBackground(): T      fun execute(onComplete: (T) -&gt; Unit, onError: (Throwable) -&gt; Unit) {         parentJob.cancel()         parentJob = Job()         launch(foregroundContext, parent = parentJob) {             try {                 val result = withContext(backgroundContext) {                     executeOnBackground()                 }                 onComplete.invoke(result)             } catch (e: CancellationException) {                 Log.d(&quot;UseCase&quot;, &quot;canceled by user&quot;)             } catch (e: Exception) {                 onError(e)             }         }     }      protected suspend fun &lt;X&gt; background(context: CoroutineContext = backgroundContext, block: suspend () -&gt; X): Deferred&lt;X&gt; {         return async(context, parent = parentJob) {             block.invoke()         }     }      fun unsubscribe() {         parentJob.cancel()     }  } <\/code><\/pre>\n<p>  \u041f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e, \u044f \u0441\u043e\u0437\u0434\u0430\u043b \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443. \u042d\u0442\u043e \u043a\u043b\u044e\u0447 \u0434\u043b\u044f \u043e\u0442\u043c\u0435\u043d\u044b \u0432\u0441\u0435\u0445 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u044b\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 UseCase. \u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435, \u0432\u0430\u0436\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u0442\u0430\u0440\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0431\u044b\u043b\u0438 \u043e\u0442\u043c\u0435\u043d\u0435\u043d\u044b, \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u0442\u044c \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u043c, \u0447\u0442\u043e \u043c\u044b \u043d\u0435 \u0443\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u043d\u0438 \u043e\u0434\u043d\u043e\u0439 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b (\u044d\u0442\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442, \u0435\u0441\u043b\u0438 \u043c\u044b \u043e\u0442\u043f\u0438\u0448\u0435\u043c\u0441\u044f \u043e\u0442 \u0434\u0430\u043d\u043d\u043e\u0433\u043e UseCase).<\/p>\n<p>  \u0422\u0430\u043a\u0436\u0435, \u044f \u0432\u044b\u0437\u044b\u0432\u0430\u044e \u0437\u0430\u043f\u0443\u0441\u043a (UI). \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u044f \u0445\u043e\u0447\u0443 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u043e\u0440\u0443\u0442\u0438\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0432 UI \u043f\u043e\u0442\u043e\u043a\u0435. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e, \u044f \u0432\u044b\u0437\u044b\u0432\u0430\u044e \u0444\u043e\u043d\u043e\u0432\u044b\u0439 \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 async \u0432 CommonPool (\u044d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434, \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043f\u043b\u043e\u0445\u0443\u044e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c). \u0412 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, async \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0438\u0442 Deffered, \u0430 \u0434\u0430\u043b\u0435\u0435, \u044f \u0432\u044b\u0437\u043e\u0432\u0443 \u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f. \u041e\u043d \u0436\u0434\u0435\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0444\u043e\u043d\u043e\u0432\u043e\u0433\u043e \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u043d\u0435\u0441\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438\u043b\u0438 \u043e\u0448\u0438\u0431\u043a\u0443.<\/p>\n<p>  \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043e \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u0438\u0437 \u0432\u0441\u0435\u0433\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043c\u044b \u0434\u0435\u043b\u0430\u043b\u0438 \u0441 RxJava. \u041d\u0438\u0436\u0435, \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432.<\/p>\n<h4><b>Map<\/b><\/h4>\n<p>  \u042f \u0441\u043a\u0430\u0447\u0430\u043b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b searchShow \u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u043b \u0438\u0445 \u0434\u043b\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 \u043d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0448\u043e\u0443.<br \/>  \u041a\u043e\u0434 \u043d\u0430 RxJava:  <\/p>\n<pre><code class=\"java\">public class SearchShows extends UseCase {     private ShowRepository showRepository;     private ResourceRepository resourceRepository;     private String query;      @Inject     public SearchShows(ShowRepository showRepository, ResourceRepository resourceRepository) {         this.showRepository = showRepository;         this.resourceRepository = resourceRepository;     }      public void setQuery(String query) {         this.query = query;     }      @Override     protected Single&lt;String&gt; buildUseCaseObservable() {         return showRepository.searchShow(query).map(showInfos -&gt; {             if (showInfos != null && !showInfos.isEmpty()                     && showInfos.get(0).getShow() != null) {                 return showInfos.get(0).getShow().getTitle();             } else {                 return resourceRepository.getNotFoundShow();             }         });     } } <\/code><\/pre>\n<p>   \u041a\u043e\u0434 \u043d\u0430 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u0445:<\/p>\n<pre><code>class SearchShows @Inject constructor(private val showRepository: ShowRepository, private val resourceRepository: ResourceRepository) :         UseCase&lt;String&gt;() {      var query: String? = null      override suspend fun executeOnBackground(): String {         query?.let {             val showsInfo = showRepository.searchShow(it)             val showName: String? = showsInfo?.getOrNull(0)?.show?.title             return showName ?: resourceRepository.notFoundShow         }         return &quot;&quot;     } } <\/code><\/pre>\n<p>  <\/p>\n<h4><b>ZIP<\/b><\/h4>\n<p>  Zip \u0432\u043e\u0437\u044c\u043c\u0435\u0442 \u0434\u0432\u0435 \u044d\u043c\u0438\u0441\u0441\u0438\u0438 \u043e\u0442 Observer \u0438 \u043f\u043e\u043b\u043e\u0436\u0438\u0442 \u0438\u0445 \u0432\u043c\u0435\u0441\u0442\u0435 \u0432 \u043d\u043e\u0432\u0443\u044e \u044d\u043c\u0438\u0441\u0441\u0438\u044e. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0441 RxJava \u0432\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0432\u044b\u0437\u043e\u0432 \u0432 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 subscribeOn \u0432 \u043a\u0430\u0436\u0434\u043e\u043c Single. \u041c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0431\u0430 \u0432 \u043e\u0434\u043d\u043e \u0432\u0440\u0435\u043c\u044f \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0438\u0445 \u0432\u043c\u0435\u0441\u0442\u0435.<\/p>\n<p>  \u041a\u043e\u0434 \u043d\u0430 RxJava:<\/p>\n<pre><code class=\"java\">public class ShowDetail extends UseCase {     private ShowRepository showRepository;     private String id;      @Inject     public SearchShows(ShowRepository showRepository) {         this.showRepository = showRepository;     }      public void setId(String id) {         this.id = id;     }      @Override     protected Single&lt;Show&gt; buildUseCaseObservable() {       Single&lt;ShowDetail&gt; singleDetail = showRepository.showDetail(id).subscribeOn(Schedulers.io());       Single&lt;ShowBanner&gt; singleBanner = showRepository.showBanner(id).subscribeOn(Schedulers.io());       return Single.zip(singleDetail, singleBanner, (detail, banner) -&gt; new Show(detail,banner)); } <\/code><\/pre>\n<p>  \u041a\u043e\u0434 \u043d\u0430 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u0445:<\/p>\n<pre><code>class SearchShows @Inject constructor(private val showRepository: ShowRepository, private val resourceRepository: ResourceRepository) :         UseCase&lt;Show&gt;() {      var id: String? = null      override suspend fun executeOnBackground(): Show {         id?.let {             val showDetail = background{                     showRepository.showDetail(it)             }             val showBanner = background{                     showRepository.showBanner(it)             }             return Show(showDetail.await(), showBanner.await())         }         return Show()     } } <\/code><\/pre>\n<p>  <\/p>\n<h4><b>FlatMap<\/b><\/h4>\n<p>  \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u044f \u0438\u0449\u0443 \u0448\u043e\u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u043c\u0435\u044e\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 (\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e 200 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c\u0438), \u044f \u043f\u043e\u043b\u0443\u0447\u0430\u044e \u0442\u0430\u043a\u0436\u0435 \u0440\u0435\u0439\u0442\u0438\u043d\u0433 \u0448\u043e\u0443. \u0412 \u043a\u043e\u043d\u0446\u0435, \u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e \u0441\u043f\u0438\u0441\u043e\u043a \u0448\u043e\u0443 \u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c\u0438 \u0440\u0435\u0439\u0442\u0438\u043d\u0433\u0430\u043c\u0438.<\/p>\n<p>  \u041a\u043e\u0434 \u043d\u0430 RxJava:<\/p>\n<pre><code class=\"java\">public class SearchShows extends UseCase {     private ShowRepository showRepository;     private String query;      @Inject     public SearchShows(ShowRepository showRepository) {         this.showRepository = showRepository;     }      public void setQuery(String query) {         this.query = query;     }      @Override     protected Single&lt;List&lt;ShowResponse&gt;&gt; buildUseCaseObservable() {         return showRepository.searchShow(query).flatMapPublisher(                 (Function&lt;List&lt;ShowInfo&gt;, Flowable&lt;ShowInfo&gt;&gt;) Flowable::fromIterable)                 .flatMapSingle((Function&lt;ShowInfo, SingleSource&lt;ShowResponse&gt;&gt;)                                 showInfo -&gt; showRepository.showRating(showInfo.getShow().getIds().getTrakt())                                         .map(rating -&gt; new ShowResponse(showInfo.getShow().getTitle(), rating                                                 .getRating())).subscribeOn(Schedulers.io()),                          false, 4).toList();     } } <\/code><\/pre>\n<p>  \u041a\u043e\u0434 \u043d\u0430 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u0445:<\/p>\n<pre><code>class SearchShows @Inject constructor(private val showRepository: ShowRepository) :         UseCase&lt;List&lt;ShowResponse&gt;&gt;() {      var query: String? = null      override suspend fun executeOnBackground(): List&lt;ShowResponse&gt; {         query?.let { query -&gt;             return showRepository.searchShow(query).map {                 background {                     val rating: Rating = showRepository.showRating(it.show!!.ids!!.trakt!!)                     ShowResponse(it.show.title!!, rating.rating)                 }             }.map {                 it.await()             }         }         return arrayListOf()     } } <\/code><\/pre>\n<p>  \u0420\u0430\u0437\u0440\u0435\u0448\u0438\u0442\u0435 \u043c\u043d\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u044c. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f RxJava, \u043c\u043e\u0451 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0434\u0438\u043d\u043e\u0447\u043d\u0443\u044e \u044d\u043c\u0438\u0441\u0441\u0438\u044e List, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044d\u043c\u0438\u0441\u0441\u0438\u0439, \u043f\u043e \u043e\u0434\u043d\u043e\u0439 \u043d\u0430 \u043a\u0430\u0436\u0434\u0443\u044e ShowInfo. \u0427\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e, \u044f \u0432\u044b\u0437\u0432\u0430\u043b flatMapPublisher. \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u044d\u043c\u0438\u0441\u0441\u0438\u0438 \u044f \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c ShowResponse, \u0438 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u0438\u0445 \u0432\u0441\u0435 \u0432 \u0441\u043f\u0438\u0441\u043e\u043a.<\/p>\n<p>  \u041c\u044b \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u043c \u0441 \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0435\u0439: List foreach \u2192 (ShowInfo \u2192 ShowRating \u2192 ShowResponse) \u2192 List.<\/p>\n<p>  \u0421 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438 \u044f \u0441\u0434\u0435\u043b\u0430\u043b map \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 List, \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u0441\u043f\u0438\u0441\u043e\u043a List&lt;Deffered&gt;.<\/p>\n<p>  \u041a\u0430\u043a \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0438\u0434\u0435\u0442\u044c, \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0441 RxJava \u043f\u0440\u043e\u0449\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c\u0438 \u0432\u044b\u0437\u043e\u0432\u0430\u043c\u0438. \u041a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u043c\u043e\u0433\u0443\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0434\u0430\u0436\u0435 flatMap, \u043a\u043e\u0442\u043e\u0440\u044b\u0435, \u043a\u0430\u043a \u044f \u0432\u0435\u0440\u044e, \u043e\u0434\u043d\u0438 \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432 RxJava.<\/p>\n<p>  \u0425\u043e\u0440\u043e\u0448\u043e \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0447\u0442\u043e \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043b\u0435\u0433\u043a\u043e\u0432\u0435\u0441\u043d\u044b\u043c\u0438 (<a href=\"https:\/\/proandroiddev.com\/kotlin-coroutines-vs-rxjava-an-initial-performance-test-68160cfc6723\">\u0437\u0434\u0435\u0441\u044c<\/a> \u043f\u0440\u0438\u043c\u0435\u0440), \u043d\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043e\u0437\u0430\u0434\u0430\u0447\u0438\u043b\u0438 \u043c\u0435\u043d\u044f. \u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435, RxJava \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u043b\u0430\u0441\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e 3.1 \u0441\u0435\u043a\u0443\u043d\u0434\u044b, \u0442\u043e\u0433\u0434\u0430 \u043a\u0430\u043a \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e 5.8 \u0441\u0435\u043a\u0443\u043d\u0434 \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043d\u0430 CommonPool.<\/p>\n<p>  \u042d\u0442\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u043e \u043c\u043d\u043e\u0439 \u0432\u043e\u043f\u0440\u043e\u0441, \u0447\u0442\u043e \u0432 \u043d\u0438\u0445 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u043d\u0435\u0443\u043c\u0435\u0441\u0442\u043d\u043e\u0435. \u041f\u043e\u0437\u0436\u0435, \u044f \u043d\u0430\u0448\u0435\u043b, \u0447\u0442\u043e \u044d\u0442\u043e. \u042f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b retrofit Call, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043b \u043f\u043e\u0442\u043e\u043a.<\/p>\n<p>  \u0414\u043b\u044f \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0438 \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u043f\u0443\u0442\u0438, \u0432\u044b\u0431\u043e\u0440 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0435\u0439 Android Studio \u0432\u044b \u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435\u0441\u044c. \u0412 \u0432\u0435\u0440\u0441\u0438\u0438 Android Studio 3.1 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043c\u044b \u043d\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u043c \u0444\u043e\u043d\u043e\u0432\u044b\u0439 \u043f\u043e\u0442\u043e\u043a. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e, \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0434\u0430\u043d\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443:  <\/p>\n<blockquote><p>implementation &#8216;ru.gildor.coroutines:kotlin-coroutines-retrofit:0.12.0&#8217;  <\/p><\/blockquote>\n<p>  \u0414\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 retrofit Call \u0434\u043b\u044f \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043f\u043e\u0442\u043e\u043a\u0430:<\/p>\n<pre><code>public suspend fun &lt;T : Any&gt; Call&lt;T&gt;.await(): T {     return suspendCancellableCoroutine { continuation -&gt;         enqueue(object : Callback&lt;T&gt; {             override fun onResponse(call: Call&lt;T&gt;?, response: Response&lt;T?&gt;) {                 if (response.isSuccessful) {                     val body = response.body()                     if (body == null) {                         continuation.resumeWithException(                             NullPointerException(&quot;Response body is null: $response&quot;)                         )                     } else {                         continuation.resume(body)                     }                 } else {                     continuation.resumeWithException(HttpException(response))                 }             }              override fun onFailure(call: Call&lt;T&gt;, t: Throwable) {                 \/\/ Don't bother with resuming the continuation if it is already cancelled.                 if (continuation.isCancelled) return                 continuation.resumeWithException(t)             }         })          registerOnCompletion(continuation)     } } <\/code><\/pre>\n<p>  \u0412 Android Studio 3.2, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u043a\u043e\u0440\u0443\u0442\u0438\u043d \u0434\u043e \u0432\u0435\u0440\u0441\u0438\u0438 0.25.0. \u042d\u0442\u0430 \u0432\u0435\u0440\u0441\u0438\u044f \u0438\u043c\u0435\u0435\u0442 CoroutineContext IO (\u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0438\u0434\u0435\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u0432 \u043c\u043e\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u0435 UseCase).<\/p>\n<p>  \u0412\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043d\u0430 CommonPool \u0431\u0435\u0437 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u0437\u0430\u043d\u044f\u043b\u043e 2.3 \u0441\u0435\u043a\u0443\u043d\u0434\u044b \u0438 2.4 \u0441\u0435\u043a\u0443\u043d\u0434\u044b \u0441 IO \u0438 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u043c\u0438 \u0432\u044b\u0437\u043e\u0432\u0430\u043c\u0438.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1000\/1*vUG7SROZLpFXX6PJk8CVmw.png\" alt=\"image\"\/><\/p>\n<p>  \u042f \u043d\u0430\u0434\u0435\u044e\u0441\u044c \u0434\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u0438\u0442 \u0432\u0430\u0441 \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d, \u0431\u043e\u043b\u0435\u0435 \u043b\u0435\u0433\u043a\u043e\u0432\u0435\u0441\u043d\u043e\u0439 \u0438, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0431\u043e\u043b\u0435\u0435 \u0431\u044b\u0441\u0442\u0440\u043e\u0439 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u0435 RxJava \u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0431\u043b\u0435\u0433\u0447\u0438\u0442 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0432\u044b \u043f\u0438\u0448\u0435\u0442\u0435 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e.<\/p><\/div>\n<p>        <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d()}}}t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>     <br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/post\/421739\/\"> https:\/\/habr.com\/post\/421739\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div data-io-article-url=\"https:\/\/habr.com\/post\/421739\/\" class=\"post__text post__text-html js-mediator-article\">\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u0432\u0430\u043c \u043f\u0435\u0440\u0435\u0432\u043e\u0434 <a href=\"https:\/\/proandroiddev.com\/i-exchanged-rxjava-for-coroutines-in-my-android-application-why-you-probably-should-do-the-same-5526dfb38d0e\">\u0441\u0442\u0430\u0442\u044c\u0438<\/a> \u0430\u0432\u0442\u043e\u0440\u0430 Paulo Sato \u043d\u0430 \u0442\u0435\u043c\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f Kotlin Coroutines \u0432\u043c\u0435\u0441\u0442\u043e RxJava \u0432 \u0441\u0432\u043e\u0438\u0445 Android \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445.<\/p>\n<p>  RxJava \u043a\u0430\u043a \u0431\u0430\u0437\u0443\u043a\u0430, \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0438 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u044b \u0435\u0451 \u043e\u0433\u043d\u0435\u0432\u043e\u0439 \u043c\u043e\u0449\u0438. \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u043e\u0439\u0434\u0435\u0442 \u0440\u0435\u0447\u044c \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0435\u0451 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438 (\u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u043c\u0438) Kotlin.<\/p>\n<p>  \u042f \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0441 RxJava \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043b\u0435\u0442. \u042d\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e \u043e\u0434\u043d\u0430 \u0438\u0437 \u043b\u0443\u0447\u0448\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e Android \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u0432 \u0443\u0434\u0430\u0440\u0435, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e, \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u0443\u0435\u0442\u0435 \u043d\u0430 Java. \u0415\u0441\u043b\u0438 \u0436\u0435 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 Kotlin, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0432 \u0433\u043e\u0440\u043e\u0434\u0435 \u043d\u043e\u0432\u044b\u0439 \u0448\u0435\u0440\u0438\u0444. <\/p>\n<p>  \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 RxJava \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0442\u043e\u043a\u0438 \u0438 \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f callback hell (\u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0437\u043d\u0430\u0435\u0442\u0435, \u0447\u0442\u043e \u044d\u0442\u043e \u0442\u0430\u043a\u043e\u0435, \u0441\u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u0441\u0435\u0431\u044f \u0441\u0447\u0430\u0441\u0442\u043b\u0438\u0432\u0447\u0438\u043a\u043e\u043c \u0438 <a href=\"https:\/\/www.quora.com\/What-is-callback-hell\">\u0432\u043e\u0442 \u043f\u043e\u0447\u0435\u043c\u0443<\/a>). \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u043c\u0435\u0442\u044c \u0432\u0432\u0438\u0434\u0443, \u0447\u0442\u043e \u0440\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u043c\u043e\u0449\u044c RxJava \u2014 \u044d\u0442\u043e \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 backpressure. \u0415\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u0435\u0451 \u0434\u043b\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u0431\u0430\u0437\u0443\u043a\u0443, \u0447\u0442\u043e\u0431\u044b \u0443\u0431\u0438\u0442\u044c \u043f\u0430\u0443\u043a\u0430. \u041e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0432\u043e\u044e \u0440\u0430\u0431\u043e\u0442\u0443, \u043d\u043e \u044d\u0442\u043e \u043f\u0435\u0440\u0435\u0431\u043e\u0440.<\/p>\n<p>  \u041e\u0434\u043d\u0438\u043c \u0437\u0430\u043c\u0435\u0442\u043d\u044b\u043c \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u043c RxJava \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u0432. \u041e\u043d\u043e \u043e\u0433\u0440\u043e\u043c\u043d\u043e \u0438 \u0438\u043c\u0435\u0435\u0442 \u0442\u0435\u043d\u0434\u0435\u043d\u0446\u0438\u044e \u0440\u0430\u0441\u043f\u043e\u043b\u0437\u0430\u0442\u044c\u0441\u044f \u043f\u043e \u0432\u0441\u0435\u043c\u0443 \u043a\u043e\u0434\u0443. \u0412 Kotlin \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u044b \u0440\u0430\u043d\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f RxJava. <\/p>\n<p>  \u041d\u043e\u2026 \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b?<\/p>\n<p>  \u041a\u043e\u0440\u0443\u0442\u0438\u043d \u2014 \u044d\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u0432 \u043f\u043e\u0442\u043e\u043a\u0435. \u041f\u043e\u0442\u043e\u043a \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043f\u043e\u043a\u0430 \u043d\u0435 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0431\u0443\u0434\u0435\u0442 \u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430 \u0431\u0435\u0437 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430.<br \/>  \u041a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0432 Kotlin \u0432\u0441\u0451 \u0435\u0449\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u044d\u043a\u0441\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u043c\u0438, \u043d\u043e \u043e\u043d\u0438 \u0432\u043e\u0448\u043b\u0438 \u0432 Kotlin 1.3, \u0442\u0430\u043a \u0447\u0442\u043e \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u043d\u0438\u0436\u0435 \u043d\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 UseCase (\u0434\u043b\u044f clean architecture), \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0439 \u0438\u0445. \u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u0432\u044b\u0437\u043e\u0432 \u043a\u043e\u0440\u0443\u0442\u0438\u043d \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d \u0432 \u043e\u0434\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u043b\u043e\u0438 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0445 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c, \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044f \u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0437\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u043d\u0443\u044e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-288727","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/288727","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=288727"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/288727\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=288727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=288727"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=288727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}