Foggy day
Android(Kotlin) - RxKotlin -2 : Observable 본문
val source = Observable.create { emitter: ObservableEmitter<String?>? ->
emitter?.onNext("Hello")
emitter?.onNext("android")
emitter?.onComplete()
}.subscribe(::println)
// source.subscribe(::println)
val source = Observable.just("Hello", "android")
source.subscribe(::println)
val stringList = listOf<String>("A", "B", "C")
val source = Observable.fromArray(stringList)
source.subscribe(::println)
val stringArrayList = arrayListOf<String>("D", "E", "F")
val sourceSecond = Observable.fromIterable(stringArrayList)
sourceSecond.subscribe(::println)
val future = Executors.newSingleThreadExecutor().submit<String> {
try {
Thread.sleep(3000)
} catch (e: InterruptedException) {
e.printStackTrace()
}
"Hello android"
}
val sourceFuture = Observable.fromFuture(future)
sourceFuture.subscribe(::println)
val publisher = Publisher { subscriber: Subscriber<in String?> ->
subscriber.onNext("A")
subscriber.onNext("C")
subscriber.onNext("E")
subscriber.onComplete()
}
val sourcePublisher = Observable.fromPublisher(publisher)
sourcePublisher.subscribe(::println)
'Android' 카테고리의 다른 글
Android - screen flickering whilefragment transaction (0) | 2021.04.03 |
---|---|
Android(Kotlin) - RxKotlin -2 : Map, flatMap (0) | 2021.03.23 |
Android(Kotlin) - RxKotlin -1 : PublishSubject (0) | 2021.03.23 |
Android - getSupportFragmentManager, getChildFragmentManager (0) | 2021.03.21 |
Android(Kotlin) - question example using assets file - 2 (0) | 2021.03.14 |