diff --git a/runtime/src/main/kotlin/kotlin/coroutines/experimental/Intrinsics.kt b/runtime/src/main/kotlin/kotlin/coroutines/experimental/Intrinsics.kt deleted file mode 100644 index c270dc53f13..00000000000 --- a/runtime/src/main/kotlin/kotlin/coroutines/experimental/Intrinsics.kt +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the LICENSE file. - */ - -package kotlin.coroutines.experimental.intrinsics - -import kotlin.coroutines.experimental.Continuation - - -/** - * Creates a coroutine without receiver and with result type [T]. - * This function creates a new, fresh instance of suspendable computation every time it is invoked. - * - * To start executing the created coroutine, invoke `resume(Unit)` on the returned [Continuation] instance. - * The [completion] continuation is invoked when coroutine completes with result or exception. - * - * This function is _unchecked_. Repeated invocation of any resume function on the resulting continuation corrupts the - * state machine of the coroutine and may result in arbitrary behaviour or exception. - */ -public actual fun (suspend () -> T).createCoroutineUnchecked( - completion: Continuation -): Continuation = errorExperimentalCoroutinesAreNoLongerSupported() - -/** - * Creates a coroutine with receiver type [R] and result type [T]. - * This function creates a new, fresh instance of suspendable computation every time it is invoked. - * - * To start executing the created coroutine, invoke `resume(Unit)` on the returned [Continuation] instance. - * The [completion] continuation is invoked when coroutine completes with result or exception. - * - * This function is _unchecked_. Repeated invocation of any resume function on the resulting continuation corrupts the - * state machine of the coroutine and may result in arbitrary behaviour or exception. - */ -public actual fun (suspend R.() -> T).createCoroutineUnchecked( - receiver: R, - completion: Continuation -): Continuation = errorExperimentalCoroutinesAreNoLongerSupported() - -/** - * Starts unintercepted coroutine without receiver and with result type [T] and executes it until its first suspension. - * Returns the result of the coroutine or throws its exception if it does not suspend or [COROUTINE_SUSPENDED] if it suspends. - * In the latter case, the [completion] continuation is invoked when coroutine completes with result or exception. - * This function is designed to be used from inside of [suspendCoroutineOrReturn] to resume the execution of a suspended - * coroutine using a reference to the suspending function. - */ -@Suppress("UNCHECKED_CAST") -@kotlin.internal.InlineOnly -public actual inline fun (suspend () -> T).startCoroutineUninterceptedOrReturn( - completion: Continuation -): Any? = errorExperimentalCoroutinesAreNoLongerSupported() - -/** - * Starts unintercepted coroutine with receiver type [R] and result type [T] and executes it until its first suspension. - * Returns the result of the coroutine or throws its exception if it does not suspend or [COROUTINE_SUSPENDED] if it suspends. - * In the latter case, the [completion] continuation is invoked when coroutine completes with result or exception. - * This function is designed to be used from inside of [suspendCoroutineOrReturn] to resume the execution of a suspended - * coroutine using a reference to the suspending function. - */ -@Suppress("UNCHECKED_CAST") -@kotlin.internal.InlineOnly -public actual inline fun (suspend R.() -> T).startCoroutineUninterceptedOrReturn( - receiver: R, - completion: Continuation -): Any? = errorExperimentalCoroutinesAreNoLongerSupported() - - - -/** - * This value is used as a return value of [suspendCoroutineOrReturn] `block` argument to state that - * the execution was suspended and will not return any result immediately. - */ -@SinceKotlin("1.1") -public actual val COROUTINE_SUSPENDED: Any get() = CoroutineSingletons.COROUTINE_SUSPENDED - -// Using enum here ensures two important properties: -// 1. It makes SafeContinuation serializable with all kinds of serialization frameworks (since all of them natively support enums) -// 2. It improves debugging experience, since you clearly see toString() value of those objects and what package they come from -private enum class CoroutineSingletons { - COROUTINE_SUSPENDED -} - -@PublishedApi -internal fun errorExperimentalCoroutinesAreNoLongerSupported(): Nothing = - error("kotlin.coroutines.experimental is no longer supported, please migrate to kotlin.coroutines") diff --git a/runtime/src/main/kotlin/kotlin/coroutines/experimental/SafeContinuation.kt b/runtime/src/main/kotlin/kotlin/coroutines/experimental/SafeContinuation.kt deleted file mode 100644 index d35aee1d12d..00000000000 --- a/runtime/src/main/kotlin/kotlin/coroutines/experimental/SafeContinuation.kt +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the LICENSE file. - */ - -package kotlin.coroutines.experimental - -import kotlin.coroutines.experimental.intrinsics.* - -// Single-threaded continuation. -@PublishedApi -internal final actual class SafeContinuation internal actual constructor( - private val delegate: Continuation, initialResult: Any?) : Continuation { - - @PublishedApi - internal actual constructor(delegate: Continuation) : this(delegate, UNDECIDED) - - actual override val context: CoroutineContext - get() = delegate.context - - private var result: Any? = initialResult - - companion object { - private val UNDECIDED: Any? = Any() - private val RESUMED: Any? = Any() - } - - private class Fail(val exception: Throwable) - - actual override fun resume(value: T) { - when { - result === UNDECIDED -> result = value - result === COROUTINE_SUSPENDED -> { - result = RESUMED - delegate.resume(value) - } - else -> throw IllegalStateException("Already resumed") - } - } - - actual override fun resumeWithException(exception: Throwable) { - when { - result === UNDECIDED -> result = Fail(exception) - result === COROUTINE_SUSPENDED -> { - result = RESUMED - delegate.resumeWithException(exception) - } - else -> throw IllegalStateException("Already resumed") - } - } - - @PublishedApi - internal actual fun getResult(): Any? { - if (this.result === UNDECIDED) this.result = COROUTINE_SUSPENDED - val result = this.result - when { - result === RESUMED -> return COROUTINE_SUSPENDED // already called continuation, indicate COROUTINE_SUSPENDED upstream - result is Fail -> throw result.exception - else -> return result // either COROUTINE_SUSPENDED or data - } - } -} \ No newline at end of file