1
1
package com.baeldung.parallelOperationsCollections
2
2
3
- import io.reactivex.Observable
4
- import io.reactivex.rxkotlin .toObservable
5
- import io.reactivex.schedulers.Schedulers
3
+ import io.reactivex.rxjava3.core. Observable
4
+ import io.reactivex.rxjava3.kotlin .toObservable
5
+ import io.reactivex.rxjava3. schedulers.Schedulers
6
6
import kotlinx.coroutines.ExperimentalCoroutinesApi
7
7
import kotlinx.coroutines.async
8
8
import kotlinx.coroutines.awaitAll
@@ -105,11 +105,10 @@ class ParallelOperationCollectionsUnitTest {
105
105
val observable = Observable .fromIterable(people)
106
106
.flatMap(
107
107
{
108
- Observable .just(it)
109
- .subscribeOn(Schedulers .computation())
110
- .doOnNext { person -> person.setAdult() }
111
- },
112
- people.size // Uses maxConcurrency for the number of elements
108
+ Observable .just(it).subscribeOn(Schedulers .computation()).doOnNext { person ->
109
+ person.setAdult()
110
+ }
111
+ }, people.size // Uses maxConcurrency for the number of elements
113
112
)
114
113
.filter { it.age > 15 }
115
114
.toList()
@@ -129,11 +128,10 @@ class ParallelOperationCollectionsUnitTest {
129
128
val observable = people.toObservable()
130
129
.flatMap(
131
130
{
132
- Observable .just(it)
133
- .subscribeOn(Schedulers .computation())
134
- .doOnNext { person -> person.setAdult() }
135
- },
136
- people.size // Uses maxConcurrency for the number of elements
131
+ Observable .just(it).subscribeOn(Schedulers .computation()).doOnNext { person ->
132
+ person.setAdult()
133
+ }
134
+ }, people.size // Uses maxConcurrency for the number of elements
137
135
).filter { it.age > 15 }
138
136
.toList()
139
137
.map { it.sortedBy { person -> person.age } }
@@ -154,8 +152,7 @@ class ParallelOperationCollectionsUnitTest {
154
152
.flatMap { Observable .just(it) } // Without using the maxConcurrency parameter, so it only uses 1 thread.
155
153
.doOnNext { person -> person.setAdult() }
156
154
.filter { it.age > 15 }.toList()
157
- .map { it.sortedBy { person -> person.age } }
158
- .blockingGet()
155
+ .map { it.sortedBy { person -> person.age } }.blockingGet()
159
156
160
157
startTime.printTotalTime()
161
158
0 commit comments