We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent bdf86fb commit b488ce5Copy full SHA for b488ce5
kotlinx-coroutines-core/common/test/flow/channels/ChannelFlowTest.kt
@@ -204,4 +204,25 @@ class ChannelFlowTest : TestBase() {
204
myFlow.collect()
205
finish(4)
206
}
207
+
208
+ @Test
209
+ fun testDoesntDispatchWhenUnnecessarilyWhenCollected() = runTest {
210
+ expect(1)
211
+ var subscribed = false
212
+ val myFlow = flow<Int> {
213
+ expect(3)
214
+ subscribed = true
215
+ yield()
216
+ expect(5)
217
+ }
218
+ launch(start = CoroutineStart.UNDISPATCHED) {
219
+ expect(2)
220
+ myFlow.collectLatest {
221
+ expectUnreached()
222
223
+ finish(6)
224
225
+ expect(4)
226
+ assertTrue(subscribed)
227
228
0 commit comments