File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed
common/kotlinx-coroutines-core-common/src Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -104,9 +104,13 @@ private open class DeferredCoroutine<T>(
104104
105105private class LazyDeferredCoroutine <T >(
106106 parentContext : CoroutineContext ,
107- private val block : suspend CoroutineScope .() -> T
107+ block : suspend CoroutineScope .() -> T
108108) : DeferredCoroutine<T>(parentContext, active = false ) {
109+ private var block: (suspend CoroutineScope .() -> T )? = block
110+
109111 override fun onStart () {
112+ val block = checkNotNull(this .block) { " Already started" }
113+ this .block = null
110114 block.startCoroutineCancellable(this , this )
111115 }
112116}
@@ -161,9 +165,13 @@ private open class StandaloneCoroutine(
161165
162166private class LazyStandaloneCoroutine (
163167 parentContext : CoroutineContext ,
164- private val block : suspend CoroutineScope .() -> Unit
168+ block : suspend CoroutineScope .() -> Unit
165169) : StandaloneCoroutine(parentContext, active = false ) {
170+ private var block: (suspend CoroutineScope .() -> Unit )? = block
171+
166172 override fun onStart () {
173+ val block = checkNotNull(this .block) { " Already started" }
174+ this .block = null
167175 block.startCoroutineCancellable(this , this )
168176 }
169177}
Original file line number Diff line number Diff line change @@ -107,8 +107,10 @@ private open class BroadcastCoroutine<E>(
107107private class LazyBroadcastCoroutine <E >(
108108 parentContext : CoroutineContext ,
109109 channel : BroadcastChannel <E >,
110- private val block : suspend ProducerScope <E >.() -> Unit
110+ block : suspend ProducerScope <E >.() -> Unit
111111) : BroadcastCoroutine<E>(parentContext, channel, active = false ) {
112+ private var block: (suspend ProducerScope <E >.() -> Unit )? = block
113+
112114 override fun openSubscription (): ReceiveChannel <E > {
113115 // open subscription _first_
114116 val subscription = _channel .openSubscription()
@@ -118,6 +120,8 @@ private class LazyBroadcastCoroutine<E>(
118120 }
119121
120122 override fun onStart () {
123+ val block = checkNotNull(this .block) { " Already started" }
124+ this .block = null
121125 block.startCoroutineCancellable(this , this )
122126 }
123127}
You can’t perform that action at this time.
0 commit comments