File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed
kotlinx-coroutines-core/common Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -61,7 +61,7 @@ public fun <T> Flow<T>.retry(
6161 try {
6262 emit(value)
6363 } catch (e: Throwable ) {
64- fromDownstream = predicate(e)
64+ fromDownstream = true
6565 throw e
6666 }
6767 }
Original file line number Diff line number Diff line change @@ -63,4 +63,39 @@ class TakeTest : TestBase() {
6363 assertEquals(42 , flow.single())
6464 assertTrue(cancelled)
6565 }
66+
67+ @Test
68+ fun takeWithRetries () = runTest {
69+ val flow = flow {
70+ expect(1 )
71+ emit(1 )
72+ expect(2 )
73+ emit(2 )
74+
75+ while (true ) {
76+ emit(42 )
77+ expectUnreached()
78+ }
79+
80+ }.retry(2 ) {
81+ expectUnreached()
82+ true
83+ }.take(2 )
84+
85+ val sum = flow.sum()
86+ assertEquals(3 , sum)
87+ finish(3 )
88+ }
89+
90+ @Test
91+ fun testNonIdempotentRetry () = runTest {
92+ var count = 0
93+ flow { while (true ) emit(1 ) }
94+ .retry { count++ % 2 != 0 }
95+ .take(1 )
96+ .collect {
97+ expect(1 )
98+ }
99+ finish(2 )
100+ }
66101}
You can’t perform that action at this time.
0 commit comments