Skip to content

Commit dfeba24

Browse files
committed
Workarounds for KT-21968 to fix JS tests
1 parent 23fb728 commit dfeba24

File tree

4 files changed

+28
-8
lines changed
  • common/kotlinx-coroutines-core-common/src/main/kotlin/kotlinx/coroutines/experimental
  • core/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental
  • js/kotlinx-coroutines-core-js/src/main/kotlin/kotlinx/coroutines/experimental

4 files changed

+28
-8
lines changed

common/kotlinx-coroutines-core-common/src/main/kotlin/kotlinx/coroutines/experimental/AbstractCoroutine.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,5 +167,17 @@ public abstract class AbstractCoroutine<in T>(
167167
@Suppress("DEPRECATION")
168168
start(block, receiver, this)
169169
}
170+
171+
// todo: This workaround for KT-21968, should be removed in the future
172+
override fun invokeOnCompletion(
173+
onCancelling: Boolean,
174+
invokeImmediately: Boolean,
175+
handler: CompletionHandler
176+
): DisposableHandle =
177+
super.invokeOnCompletion(onCancelling, invokeImmediately, handler)
178+
179+
// todo: This workaround for KT-21968, should be removed in the future
180+
override fun cancel(cause: Throwable?) =
181+
super.cancel(cause)
170182
}
171183

common/kotlinx-coroutines-core-common/src/main/kotlin/kotlinx/coroutines/experimental/CommonJob.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,23 @@ internal expect open class JobSupport(active: Boolean) : Job {
6868

6969
public final override fun getCancellationException(): CancellationException
7070
public final override fun start(): Boolean
71-
public final override fun cancel(cause: Throwable?): Boolean
7271
public final override val children: Sequence<Job>
7372

73+
public override fun cancel(cause: Throwable?): Boolean
74+
7475
public final override fun attachChild(child: Job): DisposableHandle
7576
public final override suspend fun join()
76-
public final override fun invokeOnCompletion(
77+
78+
// todo: non-final as a workaround for KT-21968, should be final in the future
79+
public override fun invokeOnCompletion(
7780
onCancelling: Boolean,
7881
invokeImmediately: Boolean,
7982
handler: CompletionHandler
8083
): DisposableHandle
8184

85+
public val isCompletedExceptionally: Boolean
86+
public fun getCompletionExceptionOrNull(): Throwable?
87+
8288
internal fun initParentJobInternal(parent: Job?)
8389
internal fun makeCompletingOnce(proposedUpdate: Any?, mode: Int): Boolean
8490
internal open fun afterCompletion(state: Any?, mode: Int)

core/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/Job.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,8 @@ internal actual open class JobSupport actual constructor(active: Boolean) : Job,
813813
public final override fun invokeOnCompletion(onCancelling_: Boolean, handler: CompletionHandler): DisposableHandle =
814814
invokeOnCompletion(onCancelling = onCancelling_, invokeImmediately = true, handler = handler)
815815

816-
public actual final override fun invokeOnCompletion(
816+
// todo: non-final as a workaround for KT-21968, should be final in the future
817+
public actual override fun invokeOnCompletion(
817818
onCancelling: Boolean,
818819
invokeImmediately: Boolean,
819820
handler: CompletionHandler
@@ -1244,9 +1245,9 @@ internal actual open class JobSupport actual constructor(active: Boolean) : Job,
12441245
* =================================================================================================
12451246
*/
12461247

1247-
public val isCompletedExceptionally: Boolean get() = state is CompletedExceptionally
1248+
public actual val isCompletedExceptionally: Boolean get() = state is CompletedExceptionally
12481249

1249-
public fun getCompletionExceptionOrNull(): Throwable? {
1250+
public actual fun getCompletionExceptionOrNull(): Throwable? {
12501251
val state = this.state
12511252
check(state !is Incomplete) { "This job has not completed yet" }
12521253
return state.exceptionOrNull

js/kotlinx-coroutines-core-js/src/main/kotlin/kotlinx/coroutines/experimental/Job.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,8 @@ internal actual open class JobSupport actual constructor(active: Boolean) : Job
555555
}
556556
}
557557

558-
public actual final override fun invokeOnCompletion(onCancelling: Boolean, invokeImmediately: Boolean, handler: CompletionHandler) =
558+
// todo: non-final as a workaround for KT-21968, should be final in the future
559+
public actual override fun invokeOnCompletion(onCancelling: Boolean, invokeImmediately: Boolean, handler: CompletionHandler) =
559560
installNode(onCancelling, invokeImmediately, makeNode(handler, onCancelling))
560561

561562
private fun installNode(
@@ -944,9 +945,9 @@ internal actual open class JobSupport actual constructor(active: Boolean) : Job
944945
* =================================================================================================
945946
*/
946947

947-
public val isCompletedExceptionally: Boolean get() = state is CompletedExceptionally
948+
public actual val isCompletedExceptionally: Boolean get() = state is CompletedExceptionally
948949

949-
public fun getCompletionExceptionOrNull(): Throwable? {
950+
public actual fun getCompletionExceptionOrNull(): Throwable? {
950951
val state = this.state
951952
check(state !is Incomplete) { "This job has not completed yet" }
952953
return state.exceptionOrNull

0 commit comments

Comments
 (0)