Reformat coroutine sources
This commit is contained in:
@@ -22,8 +22,8 @@ internal abstract class CoroutineImpl(private val resultContinuation: Continuati
|
||||
|
||||
public fun intercepted(): Continuation<Any?> =
|
||||
intercepted_
|
||||
?: (context[ContinuationInterceptor]?.interceptContinuation(this) ?: this)
|
||||
.also { intercepted_ = it }
|
||||
?: (context[ContinuationInterceptor]?.interceptContinuation(this) ?: this)
|
||||
.also { intercepted_ = it }
|
||||
|
||||
override fun resumeWith(result: Result<Any?>) {
|
||||
var current = this
|
||||
|
||||
+2
-2
@@ -67,7 +67,7 @@ internal abstract class BaseContinuationImpl(
|
||||
"Continuation at ${getStackTraceElement() ?: this::class.java.name}"
|
||||
|
||||
// --- CoroutineStackFrame implementation
|
||||
|
||||
|
||||
public override val callerFrame: CoroutineStackFrame?
|
||||
get() = completion as? CoroutineStackFrame
|
||||
|
||||
@@ -101,7 +101,7 @@ internal abstract class ContinuationImpl(
|
||||
constructor(completion: Continuation<Any?>?) : this(completion, completion?.context)
|
||||
|
||||
public override val context: CoroutineContext
|
||||
get() = _context!!
|
||||
get() = _context!!
|
||||
|
||||
@Transient
|
||||
private var intercepted: Continuation<Any?>? = null
|
||||
|
||||
@@ -11,7 +11,7 @@ import kotlin.coroutines.EmptyCoroutineContext
|
||||
import kotlin.coroutines.startCoroutine
|
||||
|
||||
/**
|
||||
* Wrapper for `suspend fun main` and `@Test suspend fun testXXX` functions.
|
||||
* Wrapper for `suspend fun main` and `@Test suspend fun testXXX` functions.
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
internal fun runSuspend(block: suspend () -> Unit) {
|
||||
|
||||
@@ -84,13 +84,15 @@ public inline class Result<out T> @PublishedApi internal constructor(
|
||||
/**
|
||||
* Returns an instance that encapsulates the given [value] as successful value.
|
||||
*/
|
||||
@InlineOnly public inline fun <T> success(value: T): Result<T> =
|
||||
@InlineOnly
|
||||
public inline fun <T> success(value: T): Result<T> =
|
||||
Result(value)
|
||||
|
||||
/**
|
||||
* Returns an instance that encapsulates the given [exception] as failure.
|
||||
*/
|
||||
@InlineOnly public inline fun <T> failure(exception: Throwable): Result<T> =
|
||||
@InlineOnly
|
||||
public inline fun <T> failure(exception: Throwable): Result<T> =
|
||||
Result(createFailure(exception))
|
||||
}
|
||||
|
||||
@@ -181,7 +183,7 @@ public inline fun <R, T : R> Result<T>.getOrElse(onFailure: (exception: Throwabl
|
||||
contract {
|
||||
callsInPlace(onFailure, InvocationKind.AT_MOST_ONCE)
|
||||
}
|
||||
return when(val exception = exceptionOrNull()) {
|
||||
return when (val exception = exceptionOrNull()) {
|
||||
null -> value as T
|
||||
else -> onFailure(exception)
|
||||
}
|
||||
@@ -216,7 +218,7 @@ public inline fun <R, T> Result<T>.fold(
|
||||
callsInPlace(onSuccess, InvocationKind.AT_MOST_ONCE)
|
||||
callsInPlace(onFailure, InvocationKind.AT_MOST_ONCE)
|
||||
}
|
||||
return when(val exception = exceptionOrNull()) {
|
||||
return when (val exception = exceptionOrNull()) {
|
||||
null -> onSuccess(value as T)
|
||||
else -> onFailure(exception)
|
||||
}
|
||||
@@ -271,11 +273,11 @@ public inline fun <R, T> Result<T>.mapCatching(transform: (value: T) -> R): Resu
|
||||
*/
|
||||
@InlineOnly
|
||||
@SinceKotlin("1.3")
|
||||
public inline fun <R, T: R> Result<T>.recover(transform: (exception: Throwable) -> R): Result<R> {
|
||||
public inline fun <R, T : R> Result<T>.recover(transform: (exception: Throwable) -> R): Result<R> {
|
||||
contract {
|
||||
callsInPlace(transform, InvocationKind.AT_MOST_ONCE)
|
||||
}
|
||||
return when(val exception = exceptionOrNull()) {
|
||||
return when (val exception = exceptionOrNull()) {
|
||||
null -> this
|
||||
else -> Result.success(transform(exception))
|
||||
}
|
||||
@@ -291,9 +293,9 @@ public inline fun <R, T: R> Result<T>.recover(transform: (exception: Throwable)
|
||||
*/
|
||||
@InlineOnly
|
||||
@SinceKotlin("1.3")
|
||||
public inline fun <R, T: R> Result<T>.recoverCatching(transform: (exception: Throwable) -> R): Result<R> {
|
||||
public inline fun <R, T : R> Result<T>.recoverCatching(transform: (exception: Throwable) -> R): Result<R> {
|
||||
val value = value // workaround for inline classes BE bug
|
||||
return when(val exception = exceptionOrNull()) {
|
||||
return when (val exception = exceptionOrNull()) {
|
||||
null -> this
|
||||
else -> runCatching { transform(exception) }
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ package kotlin.coroutines
|
||||
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
import kotlin.internal.InlineOnly
|
||||
import kotlin.jvm.JvmName
|
||||
|
||||
/**
|
||||
* Interface representing a continuation after a suspension point that returns value of type `T`.
|
||||
@@ -40,7 +39,8 @@ public annotation class RestrictsSuspension
|
||||
* Resumes the execution of the corresponding coroutine passing [value] as the return value of the last suspension point.
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@InlineOnly public inline fun <T> Continuation<T>.resume(value: T): Unit =
|
||||
@InlineOnly
|
||||
public inline fun <T> Continuation<T>.resume(value: T): Unit =
|
||||
resumeWith(Result.success(value))
|
||||
|
||||
/**
|
||||
@@ -48,7 +48,8 @@ public annotation class RestrictsSuspension
|
||||
* last suspension point.
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@InlineOnly public inline fun <T> Continuation<T>.resumeWithException(exception: Throwable): Unit =
|
||||
@InlineOnly
|
||||
public inline fun <T> Continuation<T>.resumeWithException(exception: Throwable): Unit =
|
||||
resumeWith(Result.failure(exception))
|
||||
|
||||
|
||||
@@ -56,7 +57,8 @@ public annotation class RestrictsSuspension
|
||||
* Creates [Continuation] instance with a given [context] and a given implementation of [resumeWith] method.
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@InlineOnly public inline fun <T> Continuation(
|
||||
@InlineOnly
|
||||
public inline fun <T> Continuation(
|
||||
context: CoroutineContext,
|
||||
crossinline resumeWith: (Result<T>) -> Unit
|
||||
): Continuation<T> =
|
||||
|
||||
Reference in New Issue
Block a user