Optimize startCoroutine impls, move them to common stdlib

Do not wrap initial continuation for startCoroutine in SafeContinuation

This changes leaves only internal declarations and intrinsics as platform
dependent parts of the coroutine library, the rest parts (public API)
is implemented through them in common module
This commit is contained in:
Denis Zharkov
2017-01-31 18:24:33 +03:00
parent a65d86293b
commit 6dde567be4
4 changed files with 55 additions and 91 deletions
@@ -1,31 +1,5 @@
package kotlin.coroutines.experimental
/**
* Creates 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 of exception.
* An optional [dispatcher] may be specified to customise dispatch of continuations between suspension points inside the coroutine.
*/
@SinceKotlin("1.1")
public header fun <R, T> (suspend R.() -> T).createCoroutine(
receiver: R,
completion: Continuation<T>
): Continuation<Unit>
/**
* Creates 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 of exception.
* An optional [dispatcher] may be specified to customise dispatch of continuations between suspension points inside the coroutine.
*/
@SinceKotlin("1.1")
public header fun <T> (suspend () -> T).createCoroutine(
completion: Continuation<T>
): Continuation<Unit>
@PublishedApi
internal header class SafeContinuation<in T> : Continuation<T> {
internal constructor(delegate: Continuation<T>, initialResult: Any?)
@@ -40,3 +14,14 @@ internal header class SafeContinuation<in T> : Continuation<T> {
override fun resume(value: T): Unit
override fun resumeWithException(exception: Throwable): Unit
}
@SinceKotlin("1.1")
internal header fun <T> (suspend () -> T).createCoroutineInternal(
completion: Continuation<T>
): Continuation<Unit>
@SinceKotlin("1.1")
internal header fun <R, T> (suspend R.() -> T).createCoroutineInternal(
receiver: R,
completion: Continuation<T>
): Continuation<Unit>