Skip to content

Commit 7b10c94

Browse files
committed
Better documentation on CoroutineStart parameter
1 parent 12e9a0e commit 7b10c94

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/Builders.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ import kotlin.coroutines.experimental.intrinsics.suspendCoroutineOrReturn
3232
* The [context][CoroutineScope.context] of the parent coroutine from its [scope][CoroutineScope] may be used,
3333
* in which case the [Job] of the resulting coroutine is a child of the job of the parent coroutine.
3434
*
35-
* By default, the coroutine is immediately started.
35+
* By default, the coroutine is immediately scheduled for execution.
36+
* Other options can be specified via `start` parameter. See [CoroutineStart] for details.
3637
* An optional [start] parameter can be set to [CoroutineStart.LAZY] to start coroutine _lazily_. In this case,
3738
* the coroutine [Job] is created in _new_ state. It can be explicitly started with [start][Job.start] function
3839
* and will be started implicitly on the first invocation of [join][Job.join].

kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/CoroutineStart.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,16 @@ import kotlin.coroutines.experimental.startCoroutine
2424
* Defines start option for coroutines builders.
2525
* It is used in `start` parameter of [launch], [async], and [actor][kotlinx.coroutines.experimental.channels.actor]
2626
* coroutine builder functions.
27+
*
28+
* The summary of coroutine start options is:
29+
* * [DEFAULT] -- immediately schedules coroutine for execution according to its context;
30+
* * [LAZY] -- starts coroutine lazily, only when it is needed;
31+
* * [ATOMIC] -- atomically (non-cancellably) schedules coroutine for execution according to its context;
32+
* * [UNDISPATCHED] -- immediately executes coroutine until its first suspension point _in the current thread_.
2733
*/
2834
public enum class CoroutineStart {
2935
/**
30-
* Default -- schedules coroutine for execution according to its context.
36+
* Default -- immediately schedules coroutine for execution according to its context.
3137
*
3238
* If the [CoroutineDispatcher] of the coroutine context returns `true` from [CoroutineDispatcher.isDispatchNeeded]
3339
* function as most dispatchers do, then the coroutine code is dispatched for execution later, while the code that
@@ -56,8 +62,8 @@ public enum class CoroutineStart {
5662
LAZY,
5763

5864
/**
59-
* Atomically schedules coroutines for execution according to its context. This is similar to [DEFAULT],
60-
* but the coroutine cannot be cancelled before it starts executing.
65+
* Atomically (non-cancellably) schedules coroutine for execution according to its context.
66+
* This is similar to [DEFAULT], but the coroutine cannot be cancelled before it starts executing.
6167
*
6268
* Cancellability of coroutine at suspension points depends on the particular implementation details of
6369
* suspending functions as in [DEFAULT].
@@ -72,7 +78,7 @@ public enum class CoroutineStart {
7278
UNDISPATCHED;
7379

7480
/**
75-
* Starts the corresponding block as a coroutine with this coroutine start strategy.
81+
* Starts the corresponding block with receiver as a coroutine with this coroutine start strategy.
7682
*
7783
* * [DEFAULT] uses [startCoroutineCancellable].
7884
* * [ATOMIC] uses [startCoroutine].

kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/Deferred.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ public interface Deferred<out T> : Job {
105105
* The [context][CoroutineScope.context] of the parent coroutine from its [scope][CoroutineScope] may be used,
106106
* in which case the [Job] of the resulting coroutine is a child of the job of the parent coroutine.
107107
*
108-
* By default, the coroutine is immediately started.
108+
* By default, the coroutine is immediately scheduled for execution.
109+
* Other options can be specified via `start` parameter. See [CoroutineStart] for details.
109110
* An optional [start] parameter can be set to [CoroutineStart.LAZY] to start coroutine _lazily_. In this case,,
110111
* the resulting [Deferred] is created in _new_ state. It can be explicitly started with [start][Job.start]
111112
* function and will be started implicitly on the first invocation of [join][Job.join] or [await][Deferred.await].

kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/channels/Actor.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ public interface ActorJob<in E> : Job, SendChannel<E> {
6262
* The [context][CoroutineScope.context] of the parent coroutine from its [scope][CoroutineScope] may be used,
6363
* in which case the [Job] of the resulting coroutine is a child of the job of the parent coroutine.
6464
*
65-
* By default, the coroutine is immediately started.
65+
* By default, the coroutine is immediately scheduled for execution.
66+
* Other options can be specified via `start` parameter. See [CoroutineStart] for details.
6667
* An optional [start] parameter can be set to [CoroutineStart.LAZY] to start coroutine _lazily_. In this case,
6768
* the coroutine [Job] is created in _new_ state. It can be explicitly started with [start][Job.start] function
6869
* and will be started implicitly on the first invocation of [join][Job.join] or on a first message

0 commit comments

Comments
 (0)