Drop unsupported experimental coroutines API
There is no longer expect counterpart for it in common stdlib #KT-36083 (cherry picked from commit 872d1033252407f301b18684ad26b6da6af03046)
This commit is contained in:
committed by
Vasily Levchenko
parent
a3fdca0ea3
commit
b4b608a683
@@ -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 <T> (suspend () -> T).createCoroutineUnchecked(
|
|
||||||
completion: Continuation<T>
|
|
||||||
): Continuation<Unit> = 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 <R, T> (suspend R.() -> T).createCoroutineUnchecked(
|
|
||||||
receiver: R,
|
|
||||||
completion: Continuation<T>
|
|
||||||
): Continuation<Unit> = 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 <T> (suspend () -> T).startCoroutineUninterceptedOrReturn(
|
|
||||||
completion: Continuation<T>
|
|
||||||
): 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 <R, T> (suspend R.() -> T).startCoroutineUninterceptedOrReturn(
|
|
||||||
receiver: R,
|
|
||||||
completion: Continuation<T>
|
|
||||||
): 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")
|
|
||||||
@@ -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<in T> internal actual constructor(
|
|
||||||
private val delegate: Continuation<T>, initialResult: Any?) : Continuation<T> {
|
|
||||||
|
|
||||||
@PublishedApi
|
|
||||||
internal actual constructor(delegate: Continuation<T>) : 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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user