Skip to content

LazyStandaloneCoroutine contains an val reference to block #767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions common/kotlinx-coroutines-core-common/src/Builders.common.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,13 @@ private open class DeferredCoroutine<T>(

private class LazyDeferredCoroutine<T>(
parentContext: CoroutineContext,
private val block: suspend CoroutineScope.() -> T
block: suspend CoroutineScope.() -> T
) : DeferredCoroutine<T>(parentContext, active = false) {
private var block: (suspend CoroutineScope.() -> T)? = block

override fun onStart() {
val block = checkNotNull(this.block) { "Already started" }
this.block = null
block.startCoroutineCancellable(this, this)
}
}
Expand Down Expand Up @@ -161,9 +165,13 @@ private open class StandaloneCoroutine(

private class LazyStandaloneCoroutine(
parentContext: CoroutineContext,
private val block: suspend CoroutineScope.() -> Unit
block: suspend CoroutineScope.() -> Unit
) : StandaloneCoroutine(parentContext, active = false) {
private var block: (suspend CoroutineScope.() -> Unit)? = block

override fun onStart() {
val block = checkNotNull(this.block) { "Already started" }
this.block = null
block.startCoroutineCancellable(this, this)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,10 @@ private open class BroadcastCoroutine<E>(
private class LazyBroadcastCoroutine<E>(
parentContext: CoroutineContext,
channel: BroadcastChannel<E>,
private val block: suspend ProducerScope<E>.() -> Unit
block: suspend ProducerScope<E>.() -> Unit
) : BroadcastCoroutine<E>(parentContext, channel, active = false) {
private var block: (suspend ProducerScope<E>.() -> Unit)? = block

override fun openSubscription(): ReceiveChannel<E> {
// open subscription _first_
val subscription = _channel.openSubscription()
Expand All @@ -117,6 +119,8 @@ private class LazyBroadcastCoroutine<E>(
}

override fun onStart() {
val block = checkNotNull(this.block) { "Already started" }
this.block = null
block.startCoroutineCancellable(this, this)
}
}