Skip to content

Commit 7db5553

Browse files
hharirielizarov
authored andcommitted
Split main coroutines guide into multiple files
See PR Kotlin#587
1 parent 87eaba8 commit 7db5553

25 files changed

+3935
-3740
lines changed

CHANGES.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* `currentScope` and `coroutineScope` builders are introduced to extract and provide `CoroutineScope`.
1919
* Factory methods to create `CoroutineScope` from `CoroutineContext` are introduced.
2020
* `CoroutineScope.isActive` became an extension property.
21-
* New sections about structured concurrency in core guide: ["Structured concurrency"](coroutines-guide.md#structured-concurrency), ["Scope builder"](coroutines-guide.md#scope-builder) and ["Structured concurrency with async"](coroutines-guide.md#structured-concurrency-with-async).
21+
* New sections about structured concurrency in core guide: ["Structured concurrency"](docs/coroutines-guide.md#structured-concurrency), ["Scope builder"](docs/coroutines-guide.md#scope-builder) and ["Structured concurrency with async"](docs/coroutines-guide.md#structured-concurrency-with-async).
2222
* New section in UI guide with Android example: ["Structured concurrency, lifecycle and coroutine parent-child hierarchy"](ui/coroutines-guide-ui.md#structured-concurrency,-lifecycle-and-coroutine-parent-child-hierarchy).
2323
* Deprecated reactive API is removed.
2424
* Dispatchers are renamed and grouped in the Dispatchers object (see #41 and #533):
@@ -38,7 +38,7 @@
3838
## Version 0.25.0
3939

4040
* Major rework on exception-handling and cancellation in coroutines (see #333, #452 and #451):
41-
* New ["Exception Handling" section in the guide](coroutines-guide.md#exception-handling) explains exceptions in coroutines.
41+
* New ["Exception Handling" section in the guide](docs/coroutines-guide.md#exception-handling) explains exceptions in coroutines.
4242
* Semantics of `Job.cancel` resulting `Boolean` value changed — `true` means exception was handled by the job, caller shall handle otherwise.
4343
* Exceptions are properly propagated from children to parents.
4444
* Installed `CoroutineExceptionHandler` for a family of coroutines receives one aggregated exception in case of failure.
@@ -47,7 +47,7 @@
4747
* Introduced support for thread-local elements in coroutines context (see #119):
4848
* `ThreadContextElement` API for custom thread-context sensitive context elements.
4949
* `ThreadLocal.asContextElement()` extension function to convert an arbitrary thread-local into coroutine context element.
50-
* New ["Thread-local data" subsection in the guide](coroutines-guide.md#thread-local-data) with examples.
50+
* New ["Thread-local data" subsection in the guide](docs/coroutines-guide.md#thread-local-data) with examples.
5151
* SLF4J Mapped Diagnostic Context (MDC) integration is provided via `MDCContext` element defined in [`kotlinx-coroutines-slf4j`](integration/kotlinx-coroutines-slf4j/README.md) integration module.
5252
* Introduced IO dispatcher to offload blocking I/O-intensive tasks (see #79).
5353
* Introduced `ExecutorCoroutineDispatcher` instead of `CloseableCoroutineDispatcher` (see #385).
@@ -280,7 +280,7 @@
280280
* Fixed `actor` and `produce` so that a cancellation of a Job cancels the underlying channel (closes and removes all the pending messages).
281281
* Fixed sporadic failure of `example-context-06` (see #160)
282282
* Fixed hang of `Job.start` on lazy coroutine with attached `invokeOnCompletion` handler.
283-
* A more gradual introduction to `runBlocking` and coroutines in the [guide](coroutines-guide.md) (see #166).
283+
* A more gradual introduction to `runBlocking` and coroutines in the [guide](docs/coroutines-guide.md) (see #166).
284284

285285
## Version 0.19.3
286286

@@ -331,7 +331,7 @@
331331
* When a context is explicitly specified, `newCoroutineContext` function checks if there is any
332332
interceptor/dispatcher defined in the context and uses `DefaultDispatcher` if there is none.
333333
* `DefaultDispatcher` is currently defined to be equal to `CommonPool`.
334-
* Examples in the [guide](coroutines-guide.md) now start with `launch { ... }` code and explanation on the nature
334+
* Examples in the [guide](docs/coroutines-guide.md) now start with `launch { ... }` code and explanation on the nature
335335
and the need for coroutine context starts in "Coroutine context and dispatchers" section.
336336
* Parent coroutines now wait for their children (see #125):
337337
* Job _completing_ state is introduced in documentation as a state in which parent coroutine waits for its children.
@@ -391,7 +391,7 @@
391391
## Version 0.17
392392

393393
* `CompletableDeferred` is introduced as a set-once event-like communication primitive (see #70).
394-
* [Coroutines guide](coroutines-guide.md) uses it in a section on actors.
394+
* [Coroutines guide](docs/coroutines-guide.md) uses it in a section on actors.
395395
* `CompletableDeferred` is an interface with private impl (courtesy of @fvasco, see #86).
396396
* It extends `Deferred` interface with `complete` and `completeExceptionally` functions.
397397
* `Job.join` and `Deferred.await` wait until a cancelled coroutine stops execution (see #64).
@@ -537,15 +537,15 @@
537537
* `actor` coroutine builder.
538538
* Couple more examples for "Shared mutable state and concurrency" section and
539539
"Channels are fair" section with ping-pong table example
540-
in [coroutines guide](coroutines-guide.md).
540+
in [coroutines guide](docs/coroutines-guide.md).
541541

542542
## Version 0.11-rc
543543

544544
* `select` expression with onJoin/onAwait/onSend/onReceive clauses.
545545
* `Mutex` is moved to `kotlinx.coroutines.experimental.sync` package.
546546
* `ClosedSendChannelException` is a subclass of `CancellationException` now.
547547
* New sections on "Shared mutable state and concurrency" and "Select expression"
548-
in [coroutines guide](coroutines-guide.md).
548+
in [coroutines guide](docs/coroutines-guide.md).
549549

550550
## Version 0.10-rc
551551

@@ -573,20 +573,20 @@
573573
So, lazy coroutines do not need a separate state variable to track their started/not-started (new/active) status.
574574
* Exception transparency in `Job.cancel` (original cause is rethrown).
575575
* Clarified possible states for `Job`/`CancellableContinuation`/`Deferred` in docs.
576-
* Example on async-style functions and links to API reference site from [coroutines guide](coroutines-guide.md).
576+
* Example on async-style functions and links to API reference site from [coroutines guide](docs/coroutines-guide.md).
577577

578578
## Version 0.7-beta
579579

580580
* Buffered and unbuffered channels are introduced: `Channel`, `SendChannel`, and `ReceiveChannel` interfaces,
581581
`RendezvousChannel` and `ArrayChannel` implementations, `Channel()` factory function and `buildChannel{}`
582582
coroutines builder.
583583
* `Here` context is renamed to `Unconfined` (the old name is deprecated).
584-
* A [guide on coroutines](coroutines-guide.md) is expanded: sections on contexts and channels.
584+
* A [guide on coroutines](docs/coroutines-guide.md) is expanded: sections on contexts and channels.
585585

586586
## Version 0.6-beta
587587

588588
* Switched to Kotlin version 1.1.0-beta-37.
589-
* A [guide on coroutines](coroutines-guide.md) is expanded.
589+
* A [guide on coroutines](docs/coroutines-guide.md) is expanded.
590590

591591
## Version 0.5-beta
592592

@@ -599,7 +599,7 @@
599599
has a default implementation that returns `true`.
600600
* `NonCancellable` context is introduced.
601601
* Performance optimizations for cancellable continuations (fewer objects created).
602-
* A [guide on coroutines](coroutines-guide.md) is added.
602+
* A [guide on coroutines](docs/coroutines-guide.md) is added.
603603

604604
## Version 0.4-beta
605605

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ GlobalScope.launch {
4040
* [Introduction to Coroutines](https://www.youtube.com/watch?v=_hfBv0a09Jc) (Roman Elizarov at KotlinConf 2017, [slides](https://www.slideshare.net/elizarov/introduction-to-coroutines-kotlinconf-2017))
4141
* [Deep dive into Coroutines](https://www.youtube.com/watch?v=YrrUCSi72E8) (Roman Elizarov at KotlinConf 2017, [slides](https://www.slideshare.net/elizarov/deep-dive-into-coroutines-on-jvm-kotlinconf-2017))
4242
* Guides and manuals:
43-
* [Guide to kotlinx.coroutines by example](coroutines-guide.md) (**read it first**)
43+
* [Guide to kotlinx.coroutines by example](docs/coroutines-guide.md) (**read it first**)
4444
* [Guide to UI programming with coroutines](ui/coroutines-guide-ui.md)
4545
* [Guide to reactive streams with coroutines](reactive/coroutines-guide-reactive.md)
4646
* [Change log for kotlinx.coroutines](CHANGES.md)

RELEASE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ To release new `<version>` of `kotlinx-coroutines`:
1313

1414
4. Search & replace `<old-version>` with `<version>` across the project files. Should replace in:
1515
* [`README.md`](README.md)
16-
* [`coroutines-guide.md`](coroutines-guide.md)
16+
* [`coroutines-guide.md`](docs/coroutines-guide.md)
1717
* [`gradle.properties`](gradle.properties)
1818
* [`ui/kotlinx-coroutines-android/example-app/gradle.properties`](ui/kotlinx-coroutines-android/example-app/gradle.properties)
1919
* [`ui/kotlinx-coroutines-android/animation-app/gradle.properties`](ui/kotlinx-coroutines-android/animation-app/gradle.properties)
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
2+
package kotlinx.coroutines.experimental.guide.test
3+
4+
import org.junit.Test
5+
6+
class BasicsGuideTest {
7+
8+
@Test
9+
fun testKotlinxCoroutinesExperimentalGuideBasic01() {
10+
test("KotlinxCoroutinesExperimentalGuideBasic01") { kotlinx.coroutines.experimental.guide.basic01.main(emptyArray()) }.verifyLines(
11+
"Hello,",
12+
"World!"
13+
)
14+
}
15+
16+
@Test
17+
fun testKotlinxCoroutinesExperimentalGuideBasic02() {
18+
test("KotlinxCoroutinesExperimentalGuideBasic02") { kotlinx.coroutines.experimental.guide.basic02.main(emptyArray()) }.verifyLines(
19+
"Hello,",
20+
"World!"
21+
)
22+
}
23+
24+
@Test
25+
fun testKotlinxCoroutinesExperimentalGuideBasic02b() {
26+
test("KotlinxCoroutinesExperimentalGuideBasic02b") { kotlinx.coroutines.experimental.guide.basic02b.main(emptyArray()) }.verifyLines(
27+
"Hello,",
28+
"World!"
29+
)
30+
}
31+
32+
@Test
33+
fun testKotlinxCoroutinesExperimentalGuideBasic03() {
34+
test("KotlinxCoroutinesExperimentalGuideBasic03") { kotlinx.coroutines.experimental.guide.basic03.main(emptyArray()) }.verifyLines(
35+
"Hello,",
36+
"World!"
37+
)
38+
}
39+
40+
@Test
41+
fun testKotlinxCoroutinesExperimentalGuideBasic03s() {
42+
test("KotlinxCoroutinesExperimentalGuideBasic03s") { kotlinx.coroutines.experimental.guide.basic03s.main(emptyArray()) }.verifyLines(
43+
"Hello,",
44+
"World!"
45+
)
46+
}
47+
48+
@Test
49+
fun testKotlinxCoroutinesExperimentalGuideBasic04() {
50+
test("KotlinxCoroutinesExperimentalGuideBasic04") { kotlinx.coroutines.experimental.guide.basic04.main(emptyArray()) }.verifyLines(
51+
"Task from coroutine scope",
52+
"Task from runBlocking",
53+
"Task from nested launch",
54+
"Coroutine scope is over"
55+
)
56+
}
57+
58+
@Test
59+
fun testKotlinxCoroutinesExperimentalGuideBasic05() {
60+
test("KotlinxCoroutinesExperimentalGuideBasic05") { kotlinx.coroutines.experimental.guide.basic05.main(emptyArray()) }.verifyLines(
61+
"Hello,",
62+
"World!"
63+
)
64+
}
65+
66+
@Test
67+
fun testKotlinxCoroutinesExperimentalGuideBasic05s() {
68+
test("KotlinxCoroutinesExperimentalGuideBasic05s") { kotlinx.coroutines.experimental.guide.basic05s.main(emptyArray()) }.verifyLines(
69+
"Hello,",
70+
"World!"
71+
)
72+
}
73+
74+
@Test
75+
fun testKotlinxCoroutinesExperimentalGuideBasic06() {
76+
test("KotlinxCoroutinesExperimentalGuideBasic06") { kotlinx.coroutines.experimental.guide.basic06.main(emptyArray()) }.also { lines ->
77+
check(lines.size == 1 && lines[0] == ".".repeat(100_000))
78+
}
79+
}
80+
81+
@Test
82+
fun testKotlinxCoroutinesExperimentalGuideBasic07() {
83+
test("KotlinxCoroutinesExperimentalGuideBasic07") { kotlinx.coroutines.experimental.guide.basic07.main(emptyArray()) }.verifyLines(
84+
"I'm sleeping 0 ...",
85+
"I'm sleeping 1 ...",
86+
"I'm sleeping 2 ..."
87+
)
88+
}
89+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
2+
package kotlinx.coroutines.experimental.guide.test
3+
4+
import org.junit.Test
5+
6+
class CancellationTimeOutsGuideTest {
7+
8+
@Test
9+
fun testKotlinxCoroutinesExperimentalGuideCancel01() {
10+
test("KotlinxCoroutinesExperimentalGuideCancel01") { kotlinx.coroutines.experimental.guide.cancel01.main(emptyArray()) }.verifyLines(
11+
"I'm sleeping 0 ...",
12+
"I'm sleeping 1 ...",
13+
"I'm sleeping 2 ...",
14+
"main: I'm tired of waiting!",
15+
"main: Now I can quit."
16+
)
17+
}
18+
19+
@Test
20+
fun testKotlinxCoroutinesExperimentalGuideCancel02() {
21+
test("KotlinxCoroutinesExperimentalGuideCancel02") { kotlinx.coroutines.experimental.guide.cancel02.main(emptyArray()) }.verifyLines(
22+
"I'm sleeping 0 ...",
23+
"I'm sleeping 1 ...",
24+
"I'm sleeping 2 ...",
25+
"main: I'm tired of waiting!",
26+
"I'm sleeping 3 ...",
27+
"I'm sleeping 4 ...",
28+
"main: Now I can quit."
29+
)
30+
}
31+
32+
@Test
33+
fun testKotlinxCoroutinesExperimentalGuideCancel03() {
34+
test("KotlinxCoroutinesExperimentalGuideCancel03") { kotlinx.coroutines.experimental.guide.cancel03.main(emptyArray()) }.verifyLines(
35+
"I'm sleeping 0 ...",
36+
"I'm sleeping 1 ...",
37+
"I'm sleeping 2 ...",
38+
"main: I'm tired of waiting!",
39+
"main: Now I can quit."
40+
)
41+
}
42+
43+
@Test
44+
fun testKotlinxCoroutinesExperimentalGuideCancel04() {
45+
test("KotlinxCoroutinesExperimentalGuideCancel04") { kotlinx.coroutines.experimental.guide.cancel04.main(emptyArray()) }.verifyLines(
46+
"I'm sleeping 0 ...",
47+
"I'm sleeping 1 ...",
48+
"I'm sleeping 2 ...",
49+
"main: I'm tired of waiting!",
50+
"I'm running finally",
51+
"main: Now I can quit."
52+
)
53+
}
54+
55+
@Test
56+
fun testKotlinxCoroutinesExperimentalGuideCancel05() {
57+
test("KotlinxCoroutinesExperimentalGuideCancel05") { kotlinx.coroutines.experimental.guide.cancel05.main(emptyArray()) }.verifyLines(
58+
"I'm sleeping 0 ...",
59+
"I'm sleeping 1 ...",
60+
"I'm sleeping 2 ...",
61+
"main: I'm tired of waiting!",
62+
"I'm running finally",
63+
"And I've just delayed for 1 sec because I'm non-cancellable",
64+
"main: Now I can quit."
65+
)
66+
}
67+
68+
@Test
69+
fun testKotlinxCoroutinesExperimentalGuideCancel06() {
70+
test("KotlinxCoroutinesExperimentalGuideCancel06") { kotlinx.coroutines.experimental.guide.cancel06.main(emptyArray()) }.verifyLinesStartWith(
71+
"I'm sleeping 0 ...",
72+
"I'm sleeping 1 ...",
73+
"I'm sleeping 2 ...",
74+
"Exception in thread \"main\" kotlinx.coroutines.experimental.TimeoutCancellationException: Timed out waiting for 1300 MILLISECONDS"
75+
)
76+
}
77+
78+
@Test
79+
fun testKotlinxCoroutinesExperimentalGuideCancel07() {
80+
test("KotlinxCoroutinesExperimentalGuideCancel07") { kotlinx.coroutines.experimental.guide.cancel07.main(emptyArray()) }.verifyLines(
81+
"I'm sleeping 0 ...",
82+
"I'm sleeping 1 ...",
83+
"I'm sleeping 2 ...",
84+
"Result is null"
85+
)
86+
}
87+
}

0 commit comments

Comments
 (0)