Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package com.coderefer.rxandroidexamples.intro.operators.transform
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import com.coderefer.rxandroidexamples.R
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import java.util.concurrent.TimeUnit
private const val TAG = "SwitchMapOperator"
class SwitchMapOperatorActivity : AppCompatActivity() {
lateinit var disposable: Disposable
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_switch_map_operator)
val numList = arrayListOf(1, 2, 3, 4, 5)
disposable = Observable.interval(0, 2, TimeUnit.SECONDS)
.switchMap {
Observable.interval(0,750, TimeUnit.MILLISECONDS)
}
.doOnNext {
Log.d(TAG, it.toString())
}
.observeOn(Schedulers.io())
.subscribeOn(AndroidSchedulers.mainThread())
.subscribe()
}
override fun onDestroy() {
disposable.dispose()
super.onDestroy()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.