diff --git a/app/src/main/java/keijumt/devandroid/viewmodel/AsyncViewModel.kt b/app/src/main/java/keijumt/devandroid/viewmodel/AsyncViewModel.kt index 9a976b1..6f675f3 100644 --- a/app/src/main/java/keijumt/devandroid/viewmodel/AsyncViewModel.kt +++ b/app/src/main/java/keijumt/devandroid/viewmodel/AsyncViewModel.kt @@ -1,6 +1,9 @@ package keijumt.devandroid.viewmodel import android.os.AsyncTask +import io.reactivex.Single +import io.reactivex.rxkotlin.Singles +import io.reactivex.rxkotlin.subscribeBy import keijumt.devandroid.common.Task import kotlinx.coroutines.experimental.async import kotlinx.coroutines.experimental.launch @@ -29,5 +32,17 @@ } fun rx() { + val disposable = Singles + .zip(rxCalc(3), rxCalc(5)) { num1, num2 -> num1 * num2 } + .subscribeBy( + onSuccess = { + println(it) + } + ) + addDisposable(disposable) + } + + fun rxCalc(num: Int) = Single.create { + it.onSuccess(num * num) } } \ No newline at end of file