Skip to content

Commit 266d7c1

Browse files
committed
Documentation for createCoroutine/createCoroutineUnchecked
1 parent f0be88f commit 266d7c1

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

libraries/stdlib/src/kotlin/coroutines/experimental/CoroutinesLibrary.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ public fun <T> (suspend () -> T).startCoroutine(
4949
}
5050

5151
/**
52-
* Creates coroutine with receiver type [R] and result type [T].
52+
* Creates a coroutine with receiver type [R] and result type [T].
5353
* This function creates a new, fresh instance of suspendable computation every time it is invoked.
54+
*
5455
* To start executing the created coroutine, invoke `resume(Unit)` on the returned [Continuation] instance.
5556
* The [completion] continuation is invoked when coroutine completes with result or exception.
57+
* Repeated invocation of any resume function on the resulting continuation produces [IllegalStateException].
5658
*/
5759
@SinceKotlin("1.1")
5860
@Suppress("UNCHECKED_CAST")
@@ -62,10 +64,12 @@ public fun <R, T> (suspend R.() -> T).createCoroutine(
6264
): Continuation<Unit> = SafeContinuation(createCoroutineUnchecked(receiver, completion), COROUTINE_SUSPENDED)
6365

6466
/**
65-
* Creates coroutine without receiver and with result type [T].
67+
* Creates a coroutine without receiver and with result type [T].
6668
* This function creates a new, fresh instance of suspendable computation every time it is invoked.
69+
*
6770
* To start executing the created coroutine, invoke `resume(Unit)` on the returned [Continuation] instance.
6871
* The [completion] continuation is invoked when coroutine completes with result or exception.
72+
* Repeated invocation of any resume function on the resulting continuation produces [IllegalStateException].
6973
*/
7074
@SinceKotlin("1.1")
7175
@Suppress("UNCHECKED_CAST")

libraries/stdlib/src/kotlin/coroutines/experimental/intrinsics/Intrinsics.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ public val COROUTINE_SUSPENDED: Any = Any()
5252

5353
// JVM declarations
5454

55+
/**
56+
* Creates a coroutine without receiver and with result type [T].
57+
* This function creates a new, fresh instance of suspendable computation every time it is invoked.
58+
*
59+
* To start executing the created coroutine, invoke `resume(Unit)` on the returned [Continuation] instance.
60+
* The [completion] continuation is invoked when coroutine completes with result or exception.
61+
*
62+
* This function is _unchecked_. Repeated invocation of any resume function on the resulting continuation corrupts the
63+
* state machine of the coroutine and may result in arbitrary behaviour or exception.
64+
*/
5565
@SinceKotlin("1.1")
5666
@kotlin.jvm.JvmVersion
5767
public fun <T> (suspend () -> T).createCoroutineUnchecked(
@@ -64,6 +74,16 @@ public fun <T> (suspend () -> T).createCoroutineUnchecked(
6474
else
6575
(this.create(completion) as kotlin.coroutines.experimental.jvm.internal.CoroutineImpl).facade
6676

77+
/**
78+
* Creates a coroutine with receiver type [R] and result type [T].
79+
* This function creates a new, fresh instance of suspendable computation every time it is invoked.
80+
*
81+
* To start executing the created coroutine, invoke `resume(Unit)` on the returned [Continuation] instance.
82+
* The [completion] continuation is invoked when coroutine completes with result or exception.
83+
*
84+
* This function is _unchecked_. Repeated invocation of any resume function on the resulting continuation corrupts the
85+
* state machine of the coroutine and may result in arbitrary behaviour or exception.
86+
*/
6787
@SinceKotlin("1.1")
6888
@kotlin.jvm.JvmVersion
6989
public fun <R, T> (suspend R.() -> T).createCoroutineUnchecked(

0 commit comments

Comments
 (0)