File tree 2 files changed +15
-3
lines changed
common/kotlinx-coroutines-core-common/src
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>(
104
104
105
105
private class LazyDeferredCoroutine <T >(
106
106
parentContext : CoroutineContext ,
107
- private val block : suspend CoroutineScope .() -> T
107
+ block : suspend CoroutineScope .() -> T
108
108
) : DeferredCoroutine<T>(parentContext, active = false ) {
109
+ private var block: (suspend CoroutineScope .() -> T )? = block
110
+
109
111
override fun onStart () {
112
+ val block = checkNotNull(this .block) { " Already started" }
113
+ this .block = null
110
114
block.startCoroutineCancellable(this , this )
111
115
}
112
116
}
@@ -161,9 +165,13 @@ private open class StandaloneCoroutine(
161
165
162
166
private class LazyStandaloneCoroutine (
163
167
parentContext : CoroutineContext ,
164
- private val block : suspend CoroutineScope .() -> Unit
168
+ block : suspend CoroutineScope .() -> Unit
165
169
) : StandaloneCoroutine(parentContext, active = false ) {
170
+ private var block: (suspend CoroutineScope .() -> Unit )? = block
171
+
166
172
override fun onStart () {
173
+ val block = checkNotNull(this .block) { " Already started" }
174
+ this .block = null
167
175
block.startCoroutineCancellable(this , this )
168
176
}
169
177
}
Original file line number Diff line number Diff line change @@ -106,8 +106,10 @@ private open class BroadcastCoroutine<E>(
106
106
private class LazyBroadcastCoroutine <E >(
107
107
parentContext : CoroutineContext ,
108
108
channel : BroadcastChannel <E >,
109
- private val block : suspend ProducerScope <E >.() -> Unit
109
+ block : suspend ProducerScope <E >.() -> Unit
110
110
) : BroadcastCoroutine<E>(parentContext, channel, active = false ) {
111
+ private var block: (suspend ProducerScope <E >.() -> Unit )? = block
112
+
111
113
override fun openSubscription (): ReceiveChannel <E > {
112
114
// open subscription _first_
113
115
val subscription = _channel .openSubscription()
@@ -117,6 +119,8 @@ private class LazyBroadcastCoroutine<E>(
117
119
}
118
120
119
121
override fun onStart () {
122
+ val block = checkNotNull(this .block) { " Already started" }
123
+ this .block = null
120
124
block.startCoroutineCancellable(this , this )
121
125
}
122
126
}
You can’t perform that action at this time.
0 commit comments