fix broken links for kotlin web site (#628)
* fix broken links for Kotlin web site
diff --git a/docs/basics.md b/docs/basics.md
index 443a31f..7491088 100644
--- a/docs/basics.md
+++ b/docs/basics.md
@@ -43,6 +43,8 @@
Run the following code:
+<div class="sample" markdown="1" theme="idea" data-highlight-only>
+
```kotlin
fun main(args: Array<String>) {
GlobalScope.launch { // launch new coroutine in background and continue
@@ -54,6 +56,8 @@
}
```
+</div>
+
> You can get full code [here](../core/kotlinx-coroutines-core/test/guide/example-basic-01.kt)
Run this code:
@@ -88,6 +92,8 @@
It is easy to get lost which one is blocking and which one is not.
Let's be explicit about blocking using [runBlocking] coroutine builder:
+<div class="sample" markdown="1" theme="idea" data-highlight-only>
+
```kotlin
fun main(args: Array<String>) {
GlobalScope.launch { // launch new coroutine in background and continue
@@ -101,6 +107,8 @@
}
```
+</div>
+
> You can get full code [here](../core/kotlinx-coroutines-core/test/guide/example-basic-02.kt)
<!--- TEST
@@ -114,6 +122,8 @@
This example can be also rewritten in a more idiomatic way, using `runBlocking` to wrap
the execution of the main function:
+<div class="sample" markdown="1" theme="idea" data-highlight-only>
+
```kotlin
fun main(args: Array<String>) = runBlocking { // start main coroutine
GlobalScope.launch { // launch new coroutine in background and continue
@@ -125,6 +135,8 @@
}
```
+</div>
+
> You can get full code [here](../core/kotlinx-coroutines-core/test/guide/example-basic-02b.kt)
<!--- TEST
@@ -136,6 +148,8 @@
We explicitly specify its `Unit` return type, because a well-formed `main` function in Kotlin has to return `Unit`.
This is also a way to write unit-tests for suspending functions:
+
+<div class="sample" markdown="1" theme="idea" data-highlight-only>
```kotlin
class MyTest {
@@ -146,6 +160,8 @@
}
```
+</div>
+
<!--- CLEAR -->
### Waiting for a job
@@ -153,6 +169,8 @@
Delaying for a time while another coroutine is working is not a good approach. Let's explicitly
wait (in a non-blocking way) until the background [Job] that we have launched is complete:
+<div class="sample" markdown="1" theme="idea" data-highlight-only>
+
```kotlin
fun main(args: Array<String>) = runBlocking {
val job = GlobalScope.launch { // launch new coroutine and keep a reference to its Job
@@ -164,6 +182,8 @@
}
```
+</div>
+
> You can get full code [here](../core/kotlinx-coroutines-core/test/guide/example-basic-03.kt)
<!--- TEST
@@ -193,6 +213,8 @@
an outer coroutine (`runBlocking` in our example) does not complete until all the coroutines launched
in its scope complete. Thus, we can make our example simpler:
+<div class="sample" markdown="1" theme="idea" data-highlight-only>
+
```kotlin
fun main(args: Array<String>) = runBlocking { // this: CoroutineScope
launch { // launch new coroutine in the scope of runBlocking
@@ -203,6 +225,8 @@
}
```
+</div>
+
> You can get full code [here](../core/kotlinx-coroutines-core/test/guide/example-basic-03s.kt)
<!--- TEST
@@ -216,6 +240,8 @@
complete. The main difference between [runBlocking] and [coroutineScope] is that the latter does not block the current thread
while waiting for all children to complete.
+<div class="sample" markdown="1" theme="idea" data-highlight-only>
+
```kotlin
fun main(args: Array<String>) = runBlocking { // this: CoroutineScope
launch {
@@ -237,6 +263,8 @@
}
```
+</div>
+
> You can get full code [here](../core/kotlinx-coroutines-core/test/guide/example-basic-04.kt)
<!--- TEST
@@ -254,6 +282,8 @@
just like regular functions, but their additional feature is that they can, in turn,
use other suspending functions, like `delay` in this example, to _suspend_ execution of a coroutine.
+<div class="sample" markdown="1" theme="idea" data-highlight-only>
+
```kotlin
fun main(args: Array<String>) = runBlocking {
launch { doWorld() }
@@ -267,6 +297,8 @@
}
```
+</div>
+
> You can get full code [here](../core/kotlinx-coroutines-core/test/guide/example-basic-05.kt)
<!--- TEST
@@ -280,6 +312,8 @@
method on `CoroutineScope` is one of the solutions, but it may not always be applicable as it does not make API clearer.
[currentScope] builder comes to help: it inherits current [CoroutineScope] from the coroutine context it is invoked.
+<div class="sample" markdown="1" theme="idea" data-highlight-only>
+
```kotlin
fun main(args: Array<String>) = runBlocking {
launchDoWorld()
@@ -294,6 +328,8 @@
}
```
+</div>
+
> You can get full code [here](../core/kotlinx-coroutines-core/test/guide/example-basic-05s.kt)
<!--- TEST
@@ -305,6 +341,8 @@
Run the following code:
+<div class="sample" markdown="1" theme="idea" data-highlight-only>
+
```kotlin
fun main(args: Array<String>) = runBlocking {
repeat(100_000) { // launch a lot of coroutines
@@ -316,6 +354,8 @@
}
```
+</div>
+
> You can get full code [here](../core/kotlinx-coroutines-core/test/guide/example-basic-06.kt)
<!--- TEST lines.size == 1 && lines[0] == ".".repeat(100_000) -->
@@ -328,6 +368,8 @@
The following code launches a long-running coroutine in [GlobalScope] that prints "I'm sleeping" twice a second and then
returns from the main function after some delay:
+<div class="sample" markdown="1" theme="idea" data-highlight-only>
+
```kotlin
fun main(args: Array<String>) = runBlocking {
GlobalScope.launch {
@@ -340,6 +382,8 @@
}
```
+</div>
+
> You can get full code [here](../core/kotlinx-coroutines-core/test/guide/example-basic-07.kt)
You can run and see that it prints three lines and terminates: