Provide headers for coroutine building blocks
This commit is contained in:
@@ -0,0 +1,62 @@
|
|||||||
|
package kotlin.coroutines
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts coroutine with receiver type [R] and result type [T].
|
||||||
|
* This function creates and start a new, fresh instance of suspendable computation every time it is invoked.
|
||||||
|
* 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).startCoroutine(
|
||||||
|
receiver: R,
|
||||||
|
completion: Continuation<T>
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts coroutine without receiver and with result type [T].
|
||||||
|
* This function creates and start a new, fresh instance of suspendable computation every time it is invoked.
|
||||||
|
* 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")
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
public header fun <T> (suspend () -> T).startCoroutine(
|
||||||
|
completion: Continuation<T>
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtains the current continuation instance inside suspend functions and suspends
|
||||||
|
* currently running coroutine.
|
||||||
|
*
|
||||||
|
* In this function both [Continuation.resume] and [Continuation.resumeWithException] can be used either synchronously in
|
||||||
|
* the same stack-frame where suspension function is run or asynchronously later in the same thread or
|
||||||
|
* from a different thread of execution. Repeated invocation of any resume function produces [IllegalStateException].
|
||||||
|
*/
|
||||||
|
@SinceKotlin("1.1")
|
||||||
|
public header inline suspend fun <T> suspendCoroutine(crossinline block: (Continuation<T>) -> Unit): T
|
||||||
Reference in New Issue
Block a user