File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed
main/kotlin/org/springframework/data/r2dbc/function
test/kotlin/org/springframework/data/r2dbc/function Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change 15
15
*/
16
16
package org.springframework.data.r2dbc.function
17
17
18
+ import kotlinx.coroutines.FlowPreview
19
+ import kotlinx.coroutines.flow.Flow
18
20
import kotlinx.coroutines.reactive.awaitFirstOrNull
19
21
import kotlinx.coroutines.reactive.awaitSingle
22
+ import kotlinx.coroutines.reactive.flow.asFlow
20
23
21
24
/* *
22
25
* Non-nullable Coroutines variant of [RowsFetchSpec.one].
@@ -50,5 +53,13 @@ suspend fun <T> RowsFetchSpec<T>.awaitFirst(): T =
50
53
suspend fun <T > RowsFetchSpec<T>.awaitFirstOrNull (): T ? =
51
54
first().awaitFirstOrNull()
52
55
53
- // TODO Coroutines variant of [RowsFetchSpec.all], depends on [kotlinx.coroutines#254](https://github.com/Kotlin/kotlinx.coroutines/issues/254).
54
- // suspend fun <T> RowsFetchSpec<T>.awaitAll() = all()...
56
+ /* *
57
+ * Coroutines [Flow] variant of [RowsFetchSpec.all].
58
+ *
59
+ * Backpressure is controlled by [batchSize] parameter that controls the size of in-flight elements
60
+ * and [org.reactivestreams.Subscription.request] size.
61
+ *
62
+ * @author Sebastien Deleuze
63
+ */
64
+ @FlowPreview
65
+ fun <T : Any > RowsFetchSpec<T>.flow (batchSize : Int = 1): Flow <T > = all().asFlow(batchSize)
Original file line number Diff line number Diff line change @@ -18,10 +18,13 @@ package org.springframework.data.r2dbc.function
18
18
import io.mockk.every
19
19
import io.mockk.mockk
20
20
import io.mockk.verify
21
+ import kotlinx.coroutines.FlowPreview
22
+ import kotlinx.coroutines.flow.toList
21
23
import kotlinx.coroutines.runBlocking
22
24
import org.assertj.core.api.Assertions.assertThat
23
25
import org.assertj.core.api.Assertions.assertThatExceptionOfType
24
26
import org.junit.Test
27
+ import reactor.core.publisher.Flux
25
28
import reactor.core.publisher.Mono
26
29
27
30
/* *
@@ -150,4 +153,20 @@ class RowsFetchSpecExtensionsTests {
150
153
spec.first()
151
154
}
152
155
}
156
+
157
+ @Test // gh-91
158
+ @FlowPreview
159
+ fun allAsFlow () {
160
+
161
+ val spec = mockk<RowsFetchSpec <String >>()
162
+ every { spec.all() } returns Flux .just(" foo" , " bar" , " baz" )
163
+
164
+ runBlocking {
165
+ assertThat(spec.flow().toList()).contains(" foo" , " bar" , " baz" )
166
+ }
167
+
168
+ verify {
169
+ spec.all()
170
+ }
171
+ }
153
172
}
You can’t perform that action at this time.
0 commit comments