Skip to content

Commit 66f018c

Browse files
committed
Documentation for DefaultDispatcher in the guide
1 parent c0d559b commit 66f018c

28 files changed

+211
-140
lines changed

core/kotlinx-coroutines-core/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Coroutine dispatchers implementing [CoroutineDispatcher]:
1616

1717
| **Name** | **Description**
1818
| --------------------------- | ---------------
19+
| [DefaultDispatcher] | Is equal to [CommonPool]
1920
| [CommonPool] | Confines coroutine execution to a shared pool of threads
2021
| [newSingleThreadContext] | Create new single-threaded coroutine context
2122
| [newFixedThreadPoolContext] | Creates new thread pool of a fixed size
@@ -91,6 +92,7 @@ Select expression to perform multiple suspending operations simultaneously until
9192
[Deferred]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/-deferred/index.html
9293
[runBlocking]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/run-blocking.html
9394
[CoroutineDispatcher]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/-coroutine-dispatcher/index.html
95+
[DefaultDispatcher]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/-default-dispatcher.html
9496
[CommonPool]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/-common-pool/index.html
9597
[newSingleThreadContext]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/new-single-thread-context.html
9698
[newFixedThreadPoolContext]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/new-fixed-thread-pool-context.html

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package kotlinx.coroutines.experimental.channels
1919
import kotlinx.coroutines.experimental.*
2020
import kotlinx.coroutines.experimental.selects.SelectClause2
2121
import kotlinx.coroutines.experimental.selects.SelectInstance
22+
import kotlin.coroutines.experimental.ContinuationInterceptor
2223
import kotlin.coroutines.experimental.CoroutineContext
2324

2425
/**
@@ -58,10 +59,11 @@ public interface ActorJob<in E> : Job, SendChannel<E> {
5859
* when the coroutine completes.
5960
* The running coroutine is cancelled when the its job is [cancelled][Job.cancel].
6061
*
61-
* The [context] for the new coroutine must be explicitly specified.
62-
* See [CoroutineDispatcher] for the standard [context] implementations that are provided by `kotlinx.coroutines`.
62+
* The [context] for the new coroutine can be explicitly specified.
63+
* See [CoroutineDispatcher] for the standard context implementations that are provided by `kotlinx.coroutines`.
6364
* The [context][CoroutineScope.context] of the parent coroutine from its [scope][CoroutineScope] may be used,
6465
* in which case the [Job] of the resulting coroutine is a child of the job of the parent coroutine.
66+
* If the context does not have any dispatcher nor any other [ContinuationInterceptor], then [DefaultDispatcher] is used.
6567
*
6668
* By default, the coroutine is immediately scheduled for execution.
6769
* Other options can be specified via `start` parameter. See [CoroutineStart] for details.
@@ -75,13 +77,13 @@ public interface ActorJob<in E> : Job, SendChannel<E> {
7577
*
7678
* See [newCoroutineContext] for a description of debugging facilities that are available for newly created coroutine.
7779
*
78-
* @param context context of the coroutine
79-
* @param capacity capacity of the channel's buffer (no buffer by default)
80-
* @param start coroutine start option
81-
* @param block the coroutine code
80+
* @param context context of the coroutine. The default value is [DefaultDispatcher].
81+
* @param capacity capacity of the channel's buffer (no buffer by default).
82+
* @param start coroutine start option. The default value is [CoroutineStart.DEFAULT].
83+
* @param block the coroutine code.
8284
*/
8385
public fun <E> actor(
84-
context: CoroutineContext,
86+
context: CoroutineContext = DefaultDispatcher,
8587
capacity: Int = 0,
8688
start: CoroutineStart = CoroutineStart.DEFAULT,
8789
block: suspend ActorScope<E>.() -> Unit

core/kotlinx-coroutines-core/src/test/kotlin/guide/example-basic-01.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
1818
package guide.basic.example01
1919

20-
import kotlinx.coroutines.experimental.*
20+
import kotlinx.coroutines.experimental.delay
21+
import kotlinx.coroutines.experimental.launch
2122

2223
fun main(args: Array<String>) {
23-
launch(CommonPool) { // create new coroutine in common thread pool
24+
launch { // launch new coroutine
2425
delay(1000L) // non-blocking delay for 1 second (default time unit is ms)
2526
println("World!") // print after delay
2627
}

core/kotlinx-coroutines-core/src/test/kotlin/guide/example-basic-02.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
1818
package guide.basic.example02
1919

20-
import kotlinx.coroutines.experimental.*
20+
import kotlinx.coroutines.experimental.delay
21+
import kotlinx.coroutines.experimental.launch
22+
import kotlinx.coroutines.experimental.runBlocking
2123

2224
fun main(args: Array<String>) = runBlocking<Unit> { // start main coroutine
23-
launch(CommonPool) { // create new coroutine in common thread pool
25+
launch { // launch new coroutine
2426
delay(1000L)
2527
println("World!")
2628
}

core/kotlinx-coroutines-core/src/test/kotlin/guide/example-basic-03.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
1818
package guide.basic.example03
1919

20-
import kotlinx.coroutines.experimental.*
20+
import kotlinx.coroutines.experimental.delay
21+
import kotlinx.coroutines.experimental.launch
22+
import kotlinx.coroutines.experimental.runBlocking
2123

2224
fun main(args: Array<String>) = runBlocking<Unit> {
23-
val job = launch(CommonPool) { // create new coroutine and keep a reference to its Job
25+
val job = launch { // launch new coroutine and keep a reference to its Job
2426
delay(1000L)
2527
println("World!")
2628
}

core/kotlinx-coroutines-core/src/test/kotlin/guide/example-basic-04.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
1818
package guide.basic.example04
1919

20-
import kotlinx.coroutines.experimental.*
20+
import kotlinx.coroutines.experimental.delay
21+
import kotlinx.coroutines.experimental.launch
22+
import kotlinx.coroutines.experimental.runBlocking
2123

2224
fun main(args: Array<String>) = runBlocking<Unit> {
23-
val job = launch(CommonPool) { doWorld() }
25+
val job = launch { doWorld() }
2426
println("Hello,")
2527
job.join()
2628
}

core/kotlinx-coroutines-core/src/test/kotlin/guide/example-basic-05.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
1818
package guide.basic.example05
1919

20-
import kotlinx.coroutines.experimental.*
20+
import kotlinx.coroutines.experimental.delay
21+
import kotlinx.coroutines.experimental.launch
22+
import kotlinx.coroutines.experimental.runBlocking
2123

2224
fun main(args: Array<String>) = runBlocking<Unit> {
23-
val jobs = List(100_000) { // create a lot of coroutines and list their jobs
24-
launch(CommonPool) {
25+
val jobs = List(100_000) { // launch a lot of coroutines and list their jobs
26+
launch {
2527
delay(1000L)
2628
print(".")
2729
}

core/kotlinx-coroutines-core/src/test/kotlin/guide/example-basic-06.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
1818
package guide.basic.example06
1919

20-
import kotlinx.coroutines.experimental.*
20+
import kotlinx.coroutines.experimental.delay
21+
import kotlinx.coroutines.experimental.launch
22+
import kotlinx.coroutines.experimental.runBlocking
2123

2224
fun main(args: Array<String>) = runBlocking<Unit> {
23-
launch(CommonPool) {
25+
launch {
2426
repeat(1000) { i ->
2527
println("I'm sleeping $i ...")
2628
delay(500L)

core/kotlinx-coroutines-core/src/test/kotlin/guide/example-cancel-01.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
1818
package guide.cancel.example01
1919

20-
import kotlinx.coroutines.experimental.*
20+
import kotlinx.coroutines.experimental.delay
21+
import kotlinx.coroutines.experimental.launch
22+
import kotlinx.coroutines.experimental.runBlocking
2123

2224
fun main(args: Array<String>) = runBlocking<Unit> {
23-
val job = launch(CommonPool) {
25+
val job = launch {
2426
repeat(1000) { i ->
2527
println("I'm sleeping $i ...")
2628
delay(500L)

core/kotlinx-coroutines-core/src/test/kotlin/guide/example-cancel-02.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717
// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
1818
package guide.cancel.example02
1919

20-
import kotlinx.coroutines.experimental.*
20+
import kotlinx.coroutines.experimental.cancelAndJoin
21+
import kotlinx.coroutines.experimental.delay
22+
import kotlinx.coroutines.experimental.launch
23+
import kotlinx.coroutines.experimental.runBlocking
2124

2225
fun main(args: Array<String>) = runBlocking<Unit> {
2326
val startTime = System.currentTimeMillis()
24-
val job = launch(CommonPool) {
27+
val job = launch {
2528
var nextPrintTime = startTime
2629
var i = 0
2730
while (i < 5) { // computation loop, just wastes CPU

0 commit comments

Comments
 (0)