File tree 2 files changed +20
-3
lines changed
2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -170,7 +170,7 @@ private class LazyBroadcastCoroutine<E>(
170
170
channel : BroadcastChannel <E >,
171
171
block : suspend ProducerScope <E >.() -> Unit
172
172
) : BroadcastCoroutine<E>(parentContext, channel, active = false ) {
173
- private val continuation = block.createCoroutineUnintercepted (this , this )
173
+ private val saved = saveLazyCoroutine (this , this , block )
174
174
175
175
override fun openSubscription (): ReceiveChannel <E > {
176
176
// open subscription _first_
@@ -181,6 +181,6 @@ private class LazyBroadcastCoroutine<E>(
181
181
}
182
182
183
183
override fun onStart () {
184
- continuation.startCoroutineCancellable( this )
184
+ startLazyCoroutine(saved, this , this )
185
185
}
186
186
}
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
2
+ * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3
3
*/
4
4
5
5
package kotlinx.coroutines
@@ -296,5 +296,22 @@ class WorkerDispatcherTest : TestBase() {
296
296
finish(2 )
297
297
}
298
298
299
+ @Test
300
+ fun testBroadcastAsFlow () = runTest {
301
+ expect(1 )
302
+ withContext(dispatcher) {
303
+ expect(2 )
304
+ broadcast {
305
+ expect(3 )
306
+ send(" OK" )
307
+ }.asFlow().collect {
308
+ expect(4 )
309
+ assertEquals(" OK" , it)
310
+ }
311
+ expect(5 )
312
+ }
313
+ finish(6 )
314
+ }
315
+
299
316
private data class Data (val s : String )
300
317
}
You can’t perform that action at this time.
0 commit comments