-
Notifications
You must be signed in to change notification settings - Fork 0
Combining Operators : Concat
Devrath edited this page Dec 29, 2023
·
1 revision

- The concat operator is used to concatenate the emissions of multiple Observables, one after the other, without interleaving them.
- It waits for the one Observable to complete before subscribing to the next one.
- We can also call it as synchronous.
private val observable1 = Observable.just(1,2,3)
private val observable2 = Observable.just(4,5,6)
private val observable3 = Observable.just(7,8,9)
private val observable4 = Observable.just(10,11,12)
private val concatObservable = Observable.concat(observable1,observable2,observable3,observable4)
fun concat() {
concatObservable.subscribeBy(
onNext = { println("Result-> $it") },
onError = { println("ErrorMessage-> ${it.localizedMessage}") },
onComplete = { println("Emissions are complete") }
).addTo(subscription)
}Result-> 1
Result-> 2
Result-> 3
Result-> 4
Result-> 5
Result-> 6
Result-> 7
Result-> 8
Result-> 9
Result-> 10
Result-> 11
Result-> 12
Emissions are complete