File tree 2 files changed +36
-1
lines changed
kotlinx-coroutines-core/common
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(
61
61
try {
62
62
emit(value)
63
63
} catch (e: Throwable ) {
64
- fromDownstream = predicate(e)
64
+ fromDownstream = true
65
65
throw e
66
66
}
67
67
}
Original file line number Diff line number Diff line change @@ -63,4 +63,39 @@ class TakeTest : TestBase() {
63
63
assertEquals(42 , flow.single())
64
64
assertTrue(cancelled)
65
65
}
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
+ }
66
101
}
You can’t perform that action at this time.
0 commit comments