File tree 2 files changed +19
-3
lines changed
reactive/kotlinx-coroutines-reactive
2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -31,9 +31,7 @@ public fun <T> Publisher<T>.openSubscription(request: Int = 0): ReceiveChannel<T
31
31
* Subscribes to this [Publisher] and performs the specified action for each received element.
32
32
*/
33
33
public suspend inline fun <T > Publisher<T>.consumeEach (action : (T ) -> Unit ) {
34
- val channel = openSubscription()
35
- for (x in channel) action(x)
36
- channel.cancel()
34
+ openSubscription().consumeEach(action)
37
35
}
38
36
39
37
@Suppress(" INVISIBLE_REFERENCE" , " INVISIBLE_MEMBER" )
Original file line number Diff line number Diff line change @@ -74,6 +74,24 @@ class IntegrationTest(
74
74
assertThat(cnt, IsEqual (1 ))
75
75
}
76
76
77
+ @Test
78
+ fun testFailingConsumer () = runTest {
79
+ val pub = publish {
80
+ repeat(3 ) {
81
+ expect(it + 1 ) // expect(1), expect(2) *should* be invoked
82
+ send(it)
83
+ }
84
+ }
85
+
86
+ try {
87
+ pub.consumeEach {
88
+ throw TestException ()
89
+ }
90
+ } catch (e: TestException ) {
91
+ finish(3 )
92
+ }
93
+ }
94
+
77
95
@Test
78
96
fun testNumbers () = runBlocking<Unit > {
79
97
val n = 100 * stressTestMultiplier
You can’t perform that action at this time.
0 commit comments