Make examples runnable
* Also drop args from fun main
diff --git a/core/kotlinx-coroutines-core/test/guide/example-basic-01.kt b/core/kotlinx-coroutines-core/test/guide/example-basic-01.kt
index 3cad864..d83644f 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-basic-01.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-basic-01.kt
@@ -7,7 +7,7 @@
import kotlinx.coroutines.*
-fun main(args: Array<String>) {
+fun main() {
GlobalScope.launch { // launch new coroutine in background and continue
delay(1000L) // non-blocking delay for 1 second (default time unit is ms)
println("World!") // print after delay
diff --git a/core/kotlinx-coroutines-core/test/guide/example-basic-02.kt b/core/kotlinx-coroutines-core/test/guide/example-basic-02.kt
index c85e254..a47f906 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-basic-02.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-basic-02.kt
@@ -7,7 +7,7 @@
import kotlinx.coroutines.*
-fun main(args: Array<String>) {
+fun main() {
GlobalScope.launch { // launch new coroutine in background and continue
delay(1000L)
println("World!")
diff --git a/core/kotlinx-coroutines-core/test/guide/example-basic-02b.kt b/core/kotlinx-coroutines-core/test/guide/example-basic-02b.kt
index d65ddf9..8f179fa 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-basic-02b.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-basic-02b.kt
@@ -7,7 +7,7 @@
import kotlinx.coroutines.*
-fun main(args: Array<String>) = runBlocking<Unit> { // start main coroutine
+fun main() = runBlocking<Unit> { // start main coroutine
GlobalScope.launch { // launch new coroutine in background and continue
delay(1000L)
println("World!")
diff --git a/core/kotlinx-coroutines-core/test/guide/example-basic-03.kt b/core/kotlinx-coroutines-core/test/guide/example-basic-03.kt
index f153890..861a602 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-basic-03.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-basic-03.kt
@@ -7,11 +7,13 @@
import kotlinx.coroutines.*
-fun main(args: Array<String>) = runBlocking {
+fun main() = runBlocking {
+//sampleStart
val job = GlobalScope.launch { // launch new coroutine and keep a reference to its Job
delay(1000L)
println("World!")
}
println("Hello,")
job.join() // wait until child coroutine completes
+//sampleEnd
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-basic-03s.kt b/core/kotlinx-coroutines-core/test/guide/example-basic-03s.kt
index b9b6aa2..1e1800d 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-basic-03s.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-basic-03s.kt
@@ -7,7 +7,7 @@
import kotlinx.coroutines.*
-fun main(args: Array<String>) = runBlocking { // this: CoroutineScope
+fun main() = runBlocking { // this: CoroutineScope
launch { // launch new coroutine in the scope of runBlocking
delay(1000L)
println("World!")
diff --git a/core/kotlinx-coroutines-core/test/guide/example-basic-04.kt b/core/kotlinx-coroutines-core/test/guide/example-basic-04.kt
index 76ca19b..b0e2f73 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-basic-04.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-basic-04.kt
@@ -7,7 +7,7 @@
import kotlinx.coroutines.*
-fun main(args: Array<String>) = runBlocking { // this: CoroutineScope
+fun main() = runBlocking { // this: CoroutineScope
launch {
delay(200L)
println("Task from runBlocking")
diff --git a/core/kotlinx-coroutines-core/test/guide/example-basic-05.kt b/core/kotlinx-coroutines-core/test/guide/example-basic-05.kt
index 06067f1..7a4340e 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-basic-05.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-basic-05.kt
@@ -7,7 +7,7 @@
import kotlinx.coroutines.*
-fun main(args: Array<String>) = runBlocking {
+fun main() = runBlocking {
launch { doWorld() }
println("Hello,")
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-basic-06.kt b/core/kotlinx-coroutines-core/test/guide/example-basic-06.kt
index 2f351b4..ff6db92 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-basic-06.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-basic-06.kt
@@ -7,7 +7,7 @@
import kotlinx.coroutines.*
-fun main(args: Array<String>) = runBlocking {
+fun main() = runBlocking {
repeat(100_000) { // launch a lot of coroutines
launch {
delay(1000L)
diff --git a/core/kotlinx-coroutines-core/test/guide/example-basic-07.kt b/core/kotlinx-coroutines-core/test/guide/example-basic-07.kt
index 8df75bc..58eadd6 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-basic-07.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-basic-07.kt
@@ -7,7 +7,8 @@
import kotlinx.coroutines.*
-fun main(args: Array<String>) = runBlocking {
+fun main() = runBlocking {
+//sampleStart
GlobalScope.launch {
repeat(1000) { i ->
println("I'm sleeping $i ...")
@@ -15,4 +16,5 @@
}
}
delay(1300L) // just quit after delay
+//sampleEnd
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-cancel-01.kt b/core/kotlinx-coroutines-core/test/guide/example-cancel-01.kt
index 9288873..c2a7b0b 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-cancel-01.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-cancel-01.kt
@@ -7,7 +7,8 @@
import kotlinx.coroutines.*
-fun main(args: Array<String>) = runBlocking {
+fun main() = runBlocking {
+//sampleStart
val job = launch {
repeat(1000) { i ->
println("I'm sleeping $i ...")
@@ -19,4 +20,5 @@
job.cancel() // cancels the job
job.join() // waits for job's completion
println("main: Now I can quit.")
+//sampleEnd
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-cancel-02.kt b/core/kotlinx-coroutines-core/test/guide/example-cancel-02.kt
index 1d3c82d..3618a3b 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-cancel-02.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-cancel-02.kt
@@ -7,7 +7,8 @@
import kotlinx.coroutines.*
-fun main(args: Array<String>) = runBlocking {
+fun main() = runBlocking {
+//sampleStart
val startTime = timeSource.currentTimeMillis()
val job = launch(Dispatchers.Default) {
var nextPrintTime = startTime
@@ -24,4 +25,5 @@
println("main: I'm tired of waiting!")
job.cancelAndJoin() // cancels the job and waits for its completion
println("main: Now I can quit.")
+//sampleEnd
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-cancel-03.kt b/core/kotlinx-coroutines-core/test/guide/example-cancel-03.kt
index 3d98efc..edd9ef0 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-cancel-03.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-cancel-03.kt
@@ -7,7 +7,8 @@
import kotlinx.coroutines.*
-fun main(args: Array<String>) = runBlocking {
+fun main() = runBlocking {
+//sampleStart
val startTime = timeSource.currentTimeMillis()
val job = launch(Dispatchers.Default) {
var nextPrintTime = startTime
@@ -24,4 +25,5 @@
println("main: I'm tired of waiting!")
job.cancelAndJoin() // cancels the job and waits for its completion
println("main: Now I can quit.")
+//sampleEnd
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-cancel-04.kt b/core/kotlinx-coroutines-core/test/guide/example-cancel-04.kt
index 2001e41..4d530f7 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-cancel-04.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-cancel-04.kt
@@ -7,7 +7,8 @@
import kotlinx.coroutines.*
-fun main(args: Array<String>) = runBlocking {
+fun main() = runBlocking {
+//sampleStart
val job = launch {
try {
repeat(1000) { i ->
@@ -22,4 +23,5 @@
println("main: I'm tired of waiting!")
job.cancelAndJoin() // cancels the job and waits for its completion
println("main: Now I can quit.")
+//sampleEnd
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-cancel-05.kt b/core/kotlinx-coroutines-core/test/guide/example-cancel-05.kt
index 530fff1..d977d4e 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-cancel-05.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-cancel-05.kt
@@ -7,7 +7,8 @@
import kotlinx.coroutines.*
-fun main(args: Array<String>) = runBlocking {
+fun main() = runBlocking {
+//sampleStart
val job = launch {
try {
repeat(1000) { i ->
@@ -26,4 +27,5 @@
println("main: I'm tired of waiting!")
job.cancelAndJoin() // cancels the job and waits for its completion
println("main: Now I can quit.")
+//sampleEnd
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-cancel-06.kt b/core/kotlinx-coroutines-core/test/guide/example-cancel-06.kt
index 84f3038..da8ecbd 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-cancel-06.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-cancel-06.kt
@@ -7,11 +7,13 @@
import kotlinx.coroutines.*
-fun main(args: Array<String>) = runBlocking {
+fun main() = runBlocking {
+//sampleStart
withTimeout(1300L) {
repeat(1000) { i ->
println("I'm sleeping $i ...")
delay(500L)
}
}
+//sampleEnd
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-cancel-07.kt b/core/kotlinx-coroutines-core/test/guide/example-cancel-07.kt
index 4596c30..3fbbd09 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-cancel-07.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-cancel-07.kt
@@ -7,7 +7,8 @@
import kotlinx.coroutines.*
-fun main(args: Array<String>) = runBlocking {
+fun main() = runBlocking {
+//sampleStart
val result = withTimeoutOrNull(1300L) {
repeat(1000) { i ->
println("I'm sleeping $i ...")
@@ -16,4 +17,5 @@
"Done" // will get cancelled before it produces this result
}
println("Result is $result")
+//sampleEnd
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-channel-01.kt b/core/kotlinx-coroutines-core/test/guide/example-channel-01.kt
index 79013bb..ab437ed 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-channel-01.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-channel-01.kt
@@ -8,7 +8,8 @@
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.*
-fun main(args: Array<String>) = runBlocking {
+fun main() = runBlocking {
+//sampleStart
val channel = Channel<Int>()
launch {
// this might be heavy CPU-consuming computation or async logic, we'll just send five squares
@@ -17,4 +18,5 @@
// here we print five received integers:
repeat(5) { println(channel.receive()) }
println("Done!")
+//sampleEnd
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-channel-02.kt b/core/kotlinx-coroutines-core/test/guide/example-channel-02.kt
index 3489545..d65f0f2 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-channel-02.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-channel-02.kt
@@ -8,7 +8,8 @@
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.*
-fun main(args: Array<String>) = runBlocking {
+fun main() = runBlocking {
+//sampleStart
val channel = Channel<Int>()
launch {
for (x in 1..5) channel.send(x * x)
@@ -17,4 +18,5 @@
// here we print received values using `for` loop (until the channel is closed)
for (y in channel) println(y)
println("Done!")
+//sampleEnd
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-channel-03.kt b/core/kotlinx-coroutines-core/test/guide/example-channel-03.kt
index 4bce963..84419aa 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-channel-03.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-channel-03.kt
@@ -12,8 +12,10 @@
for (x in 1..5) send(x * x)
}
-fun main(args: Array<String>) = runBlocking {
+fun main() = runBlocking {
+//sampleStart
val squares = produceSquares()
squares.consumeEach { println(it) }
println("Done!")
+//sampleEnd
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-channel-04.kt b/core/kotlinx-coroutines-core/test/guide/example-channel-04.kt
index f4a4f83..eefbf2a 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-channel-04.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-channel-04.kt
@@ -8,19 +8,24 @@
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.*
-fun CoroutineScope.produceNumbers() = produce<Int> {
- var x = 1
- while (true) send(x++) // infinite stream of integers starting from 1
-}
-
-fun CoroutineScope.square(numbers: ReceiveChannel<Int>): ReceiveChannel<Int> = produce {
- for (x in numbers) send(x * x)
-}
-
-fun main(args: Array<String>) = runBlocking {
+fun main() = runBlocking {
+//sampleStart
val numbers = produceNumbers() // produces integers from 1 and on
val squares = square(numbers) // squares integers
for (i in 1..5) println(squares.receive()) // print first five
println("Done!") // we are done
coroutineContext.cancelChildren() // cancel children coroutines
+//sampleEnd
+}
+
+fun CoroutineScope.produceSquares(): ReceiveChannel<Int> = produce {
+ for (x in 1..5) send(x * x)
+}
+
+fun CoroutineScope.produceNumbers() = produce<Int> {
+ var x = 1
+ while (true) send(x++) // infinite stream of integers starting from 1
+}
+fun CoroutineScope.square(numbers: ReceiveChannel<Int>): ReceiveChannel<Int> = produce {
+ for (x in numbers) send(x * x)
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-channel-05.kt b/core/kotlinx-coroutines-core/test/guide/example-channel-05.kt
index ce1e999..5f9d247 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-channel-05.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-channel-05.kt
@@ -7,7 +7,18 @@
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.*
-import kotlin.coroutines.*
+
+fun main() = runBlocking {
+//sampleStart
+ var cur = numbersFrom(2)
+ for (i in 1..10) {
+ val prime = cur.receive()
+ println(prime)
+ cur = filter(cur, prime)
+ }
+ coroutineContext.cancelChildren() // cancel all children to let main finish
+//sampleEnd
+}
fun CoroutineScope.numbersFrom(start: Int) = produce<Int> {
var x = start
@@ -17,13 +28,3 @@
fun CoroutineScope.filter(numbers: ReceiveChannel<Int>, prime: Int) = produce<Int> {
for (x in numbers) if (x % prime != 0) send(x)
}
-
-fun main(args: Array<String>) = runBlocking {
- var cur = numbersFrom(2)
- for (i in 1..10) {
- val prime = cur.receive()
- println(prime)
- cur = filter(cur, prime)
- }
- coroutineContext.cancelChildren() // cancel all children to let main finish
-}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-channel-06.kt b/core/kotlinx-coroutines-core/test/guide/example-channel-06.kt
index c9837d0..7224ffa 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-channel-06.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-channel-06.kt
@@ -8,6 +8,15 @@
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.*
+fun main() = runBlocking<Unit> {
+//sampleStart
+ val producer = produceNumbers()
+ repeat(5) { launchProcessor(it, producer) }
+ delay(950)
+ producer.cancel() // cancel producer coroutine and thus kill them all
+//sampleEnd
+}
+
fun CoroutineScope.produceNumbers() = produce<Int> {
var x = 1 // start from 1
while (true) {
@@ -21,10 +30,3 @@
println("Processor #$id received $msg")
}
}
-
-fun main(args: Array<String>) = runBlocking<Unit> {
- val producer = produceNumbers()
- repeat(5) { launchProcessor(it, producer) }
- delay(950)
- producer.cancel() // cancel producer coroutine and thus kill them all
-}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-channel-07.kt b/core/kotlinx-coroutines-core/test/guide/example-channel-07.kt
index 6f84775..64df2ec 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-channel-07.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-channel-07.kt
@@ -7,16 +7,9 @@
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.*
-import kotlin.coroutines.*
-suspend fun sendString(channel: SendChannel<String>, s: String, time: Long) {
- while (true) {
- delay(time)
- channel.send(s)
- }
-}
-
-fun main(args: Array<String>) = runBlocking {
+fun main() = runBlocking {
+//sampleStart
val channel = Channel<String>()
launch { sendString(channel, "foo", 200L) }
launch { sendString(channel, "BAR!", 500L) }
@@ -24,4 +17,12 @@
println(channel.receive())
}
coroutineContext.cancelChildren() // cancel all children to let main finish
+//sampleEnd
+}
+
+suspend fun sendString(channel: SendChannel<String>, s: String, time: Long) {
+ while (true) {
+ delay(time)
+ channel.send(s)
+ }
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-channel-08.kt b/core/kotlinx-coroutines-core/test/guide/example-channel-08.kt
index 928d03b..f1e9d9b 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-channel-08.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-channel-08.kt
@@ -7,9 +7,9 @@
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.*
-import kotlin.coroutines.*
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main() = runBlocking<Unit> {
+//sampleStart
val channel = Channel<Int>(4) // create buffered channel
val sender = launch { // launch sender coroutine
repeat(10) {
@@ -20,4 +20,5 @@
// don't receive anything... just wait....
delay(1000)
sender.cancel() // cancel sender coroutine
+//sampleEnd
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-channel-09.kt b/core/kotlinx-coroutines-core/test/guide/example-channel-09.kt
index c5d6dcd..ee7afab 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-channel-09.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-channel-09.kt
@@ -7,11 +7,11 @@
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.*
-import kotlin.coroutines.*
+//sampleStart
data class Ball(var hits: Int)
-fun main(args: Array<String>) = runBlocking {
+fun main() = runBlocking {
val table = Channel<Ball>() // a shared table
launch { player("ping", table) }
launch { player("pong", table) }
@@ -28,3 +28,4 @@
table.send(ball) // send the ball back
}
}
+//sampleEnd
diff --git a/core/kotlinx-coroutines-core/test/guide/example-channel-10.kt b/core/kotlinx-coroutines-core/test/guide/example-channel-10.kt
index 23d61cd..4615e30 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-channel-10.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-channel-10.kt
@@ -8,7 +8,7 @@
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.*
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main() = runBlocking<Unit> {
val tickerChannel = ticker(delayMillis = 100, initialDelayMillis = 0) // create ticker channel
var nextElement = withTimeoutOrNull(1) { tickerChannel.receive() }
println("Initial element is available immediately: $nextElement") // initial delay hasn't passed yet
diff --git a/core/kotlinx-coroutines-core/test/guide/example-compose-01.kt b/core/kotlinx-coroutines-core/test/guide/example-compose-01.kt
index e593b29..6c027e4 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-compose-01.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-compose-01.kt
@@ -8,6 +8,17 @@
import kotlinx.coroutines.*
import kotlin.system.*
+fun main() = runBlocking<Unit> {
+//sampleStart
+ val time = measureTimeMillis {
+ val one = doSomethingUsefulOne()
+ val two = doSomethingUsefulTwo()
+ println("The answer is ${one + two}")
+ }
+ println("Completed in $time ms")
+//sampleEnd
+}
+
suspend fun doSomethingUsefulOne(): Int {
delay(1000L) // pretend we are doing something useful here
return 13
@@ -17,12 +28,3 @@
delay(1000L) // pretend we are doing something useful here, too
return 29
}
-
-fun main(args: Array<String>) = runBlocking<Unit> {
- val time = measureTimeMillis {
- val one = doSomethingUsefulOne()
- val two = doSomethingUsefulTwo()
- println("The answer is ${one + two}")
- }
- println("Completed in $time ms")
-}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-compose-02.kt b/core/kotlinx-coroutines-core/test/guide/example-compose-02.kt
index 0890eef..1cb75d9 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-compose-02.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-compose-02.kt
@@ -8,6 +8,17 @@
import kotlinx.coroutines.*
import kotlin.system.*
+fun main() = runBlocking<Unit> {
+//sampleStart
+ val time = measureTimeMillis {
+ val one = async { doSomethingUsefulOne() }
+ val two = async { doSomethingUsefulTwo() }
+ println("The answer is ${one.await() + two.await()}")
+ }
+ println("Completed in $time ms")
+//sampleEnd
+}
+
suspend fun doSomethingUsefulOne(): Int {
delay(1000L) // pretend we are doing something useful here
return 13
@@ -17,12 +28,3 @@
delay(1000L) // pretend we are doing something useful here, too
return 29
}
-
-fun main(args: Array<String>) = runBlocking<Unit> {
- val time = measureTimeMillis {
- val one = async { doSomethingUsefulOne() }
- val two = async { doSomethingUsefulTwo() }
- println("The answer is ${one.await() + two.await()}")
- }
- println("Completed in $time ms")
-}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-compose-03.kt b/core/kotlinx-coroutines-core/test/guide/example-compose-03.kt
index 925922e..4a919fb 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-compose-03.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-compose-03.kt
@@ -8,17 +8,8 @@
import kotlinx.coroutines.*
import kotlin.system.*
-suspend fun doSomethingUsefulOne(): Int {
- delay(1000L) // pretend we are doing something useful here
- return 13
-}
-
-suspend fun doSomethingUsefulTwo(): Int {
- delay(1000L) // pretend we are doing something useful here, too
- return 29
-}
-
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main() = runBlocking<Unit> {
+//sampleStart
val time = measureTimeMillis {
val one = async(start = CoroutineStart.LAZY) { doSomethingUsefulOne() }
val two = async(start = CoroutineStart.LAZY) { doSomethingUsefulTwo() }
@@ -28,4 +19,15 @@
println("The answer is ${one.await() + two.await()}")
}
println("Completed in $time ms")
+//sampleEnd
+}
+
+suspend fun doSomethingUsefulOne(): Int {
+ delay(1000L) // pretend we are doing something useful here
+ return 13
+}
+
+suspend fun doSomethingUsefulTwo(): Int {
+ delay(1000L) // pretend we are doing something useful here, too
+ return 29
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-compose-04.kt b/core/kotlinx-coroutines-core/test/guide/example-compose-04.kt
index af6e2fe..159d0fb 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-compose-04.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-compose-04.kt
@@ -8,28 +8,9 @@
import kotlinx.coroutines.*
import kotlin.system.*
-suspend fun doSomethingUsefulOne(): Int {
- delay(1000L) // pretend we are doing something useful here
- return 13
-}
-
-suspend fun doSomethingUsefulTwo(): Int {
- delay(1000L) // pretend we are doing something useful here, too
- return 29
-}
-
-// The result type of somethingUsefulOneAsync is Deferred<Int>
-fun somethingUsefulOneAsync() = GlobalScope.async {
- doSomethingUsefulOne()
-}
-
-// The result type of somethingUsefulTwoAsync is Deferred<Int>
-fun somethingUsefulTwoAsync() = GlobalScope.async {
- doSomethingUsefulTwo()
-}
-
+//sampleStart
// note, that we don't have `runBlocking` to the right of `main` in this example
-fun main(args: Array<String>) {
+fun main() {
val time = measureTimeMillis {
// we can initiate async actions outside of a coroutine
val one = somethingUsefulOneAsync()
@@ -42,3 +23,22 @@
}
println("Completed in $time ms")
}
+//sampleEnd
+
+fun somethingUsefulOneAsync() = GlobalScope.async {
+ doSomethingUsefulOne()
+}
+
+fun somethingUsefulTwoAsync() = GlobalScope.async {
+ doSomethingUsefulTwo()
+}
+
+suspend fun doSomethingUsefulOne(): Int {
+ delay(1000L) // pretend we are doing something useful here
+ return 13
+}
+
+suspend fun doSomethingUsefulTwo(): Int {
+ delay(1000L) // pretend we are doing something useful here, too
+ return 29
+}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-compose-05.kt b/core/kotlinx-coroutines-core/test/guide/example-compose-05.kt
index 4a244d4..07c0e97 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-compose-05.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-compose-05.kt
@@ -8,14 +8,13 @@
import kotlinx.coroutines.*
import kotlin.system.*
-suspend fun doSomethingUsefulOne(): Int {
- delay(1000L) // pretend we are doing something useful here
- return 13
-}
-
-suspend fun doSomethingUsefulTwo(): Int {
- delay(1000L) // pretend we are doing something useful here, too
- return 29
+fun main() = runBlocking<Unit> {
+//sampleStart
+ val time = measureTimeMillis {
+ println("The answer is ${concurrentSum()}")
+ }
+ println("Completed in $time ms")
+//sampleEnd
}
suspend fun concurrentSum(): Int = coroutineScope {
@@ -24,9 +23,12 @@
one.await() + two.await()
}
-fun main(args: Array<String>) = runBlocking<Unit> {
- val time = measureTimeMillis {
- println("The answer is ${concurrentSum()}")
- }
- println("Completed in $time ms")
+suspend fun doSomethingUsefulOne(): Int {
+ delay(1000L) // pretend we are doing something useful here
+ return 13
+}
+
+suspend fun doSomethingUsefulTwo(): Int {
+ delay(1000L) // pretend we are doing something useful here, too
+ return 29
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-compose-06.kt b/core/kotlinx-coroutines-core/test/guide/example-compose-06.kt
index d128896..6fc92a2 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-compose-06.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-compose-06.kt
@@ -6,19 +6,8 @@
package kotlinx.coroutines.guide.compose06
import kotlinx.coroutines.*
-import kotlin.system.*
-suspend fun doSomethingUsefulOne(): Int {
- delay(1000L) // pretend we are doing something useful here
- return 13
-}
-
-suspend fun doSomethingUsefulTwo(): Int {
- delay(1000L) // pretend we are doing something useful here, too
- return 29
-}
-
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main() = runBlocking<Unit> {
try {
failedConcurrentSum()
} catch(e: ArithmeticException) {
diff --git a/core/kotlinx-coroutines-core/test/guide/example-context-01.kt b/core/kotlinx-coroutines-core/test/guide/example-context-01.kt
index 65f2ece..1471f72 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-context-01.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-context-01.kt
@@ -6,9 +6,9 @@
package kotlinx.coroutines.guide.context01
import kotlinx.coroutines.*
-import kotlin.coroutines.*
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main() = runBlocking<Unit> {
+//sampleStart
launch { // context of the parent, main runBlocking coroutine
println("main runBlocking : I'm working in thread ${Thread.currentThread().name}")
}
@@ -21,4 +21,5 @@
launch(newSingleThreadContext("MyOwnThread")) { // will get its own new thread
println("newSingleThreadContext: I'm working in thread ${Thread.currentThread().name}")
}
+//sampleEnd
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-context-02.kt b/core/kotlinx-coroutines-core/test/guide/example-context-02.kt
index 038102d..7a29aed 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-context-02.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-context-02.kt
@@ -6,9 +6,9 @@
package kotlinx.coroutines.guide.context02
import kotlinx.coroutines.*
-import kotlin.coroutines.*
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main() = runBlocking<Unit> {
+//sampleStart
launch(Dispatchers.Unconfined) { // not confined -- will work with main thread
println("Unconfined : I'm working in thread ${Thread.currentThread().name}")
delay(500)
@@ -19,4 +19,5 @@
delay(1000)
println("main runBlocking: After delay in thread ${Thread.currentThread().name}")
}
+//sampleEnd
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-context-03.kt b/core/kotlinx-coroutines-core/test/guide/example-context-03.kt
index 9e50724..5740495 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-context-03.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-context-03.kt
@@ -6,11 +6,11 @@
package kotlinx.coroutines.guide.context03
import kotlinx.coroutines.*
-import kotlin.coroutines.*
fun log(msg: String) = println("[${Thread.currentThread().name}] $msg")
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main() = runBlocking<Unit> {
+//sampleStart
val a = async {
log("I'm computing a piece of the answer")
6
@@ -20,4 +20,5 @@
7
}
log("The answer is ${a.await() * b.await()}")
+//sampleEnd
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-context-04.kt b/core/kotlinx-coroutines-core/test/guide/example-context-04.kt
index 45f968b..6624252 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-context-04.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-context-04.kt
@@ -9,7 +9,8 @@
fun log(msg: String) = println("[${Thread.currentThread().name}] $msg")
-fun main(args: Array<String>) {
+fun main() {
+//sampleStart
newSingleThreadContext("Ctx1").use { ctx1 ->
newSingleThreadContext("Ctx2").use { ctx2 ->
runBlocking(ctx1) {
@@ -21,4 +22,5 @@
}
}
}
+//sampleEnd
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-context-05.kt b/core/kotlinx-coroutines-core/test/guide/example-context-05.kt
index 0dca2a9..f39ffd9 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-context-05.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-context-05.kt
@@ -6,8 +6,9 @@
package kotlinx.coroutines.guide.context05
import kotlinx.coroutines.*
-import kotlin.coroutines.*
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main() = runBlocking<Unit> {
+//sampleStart
println("My job is ${coroutineContext[Job]}")
+//sampleEnd
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-context-06.kt b/core/kotlinx-coroutines-core/test/guide/example-context-06.kt
index d4bc14b..ba0b04c 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-context-06.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-context-06.kt
@@ -6,9 +6,9 @@
package kotlinx.coroutines.guide.context06
import kotlinx.coroutines.*
-import kotlin.coroutines.*
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main() = runBlocking<Unit> {
+//sampleStart
// launch a coroutine to process some kind of incoming request
val request = launch {
// it spawns two other jobs, one with GlobalScope
@@ -29,4 +29,5 @@
request.cancel() // cancel processing of the request
delay(1000) // delay a second to see what happens
println("main: Who has survived request cancellation?")
+//sampleEnd
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-context-07.kt b/core/kotlinx-coroutines-core/test/guide/example-context-07.kt
index 478e2a8..992e672 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-context-07.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-context-07.kt
@@ -6,9 +6,9 @@
package kotlinx.coroutines.guide.context07
import kotlinx.coroutines.*
-import kotlin.coroutines.*
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main() = runBlocking<Unit> {
+//sampleStart
// launch a coroutine to process some kind of incoming request
val request = launch {
repeat(3) { i -> // launch a few children jobs
@@ -21,4 +21,5 @@
}
request.join() // wait for completion of the request, including all its children
println("Now processing of the request is complete")
+//sampleEnd
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-context-08.kt b/core/kotlinx-coroutines-core/test/guide/example-context-08.kt
index dd1d482..bcc754a 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-context-08.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-context-08.kt
@@ -9,7 +9,8 @@
fun log(msg: String) = println("[${Thread.currentThread().name}] $msg")
-fun main(args: Array<String>) = runBlocking(CoroutineName("main")) {
+fun main() = runBlocking(CoroutineName("main")) {
+//sampleStart
log("Started main coroutine")
// run two background value computations
val v1 = async(CoroutineName("v1coroutine")) {
@@ -23,4 +24,5 @@
6
}
log("The answer for v1 / v2 = ${v1.await() / v2.await()}")
+//sampleEnd
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-context-09.kt b/core/kotlinx-coroutines-core/test/guide/example-context-09.kt
index 7603c46..58b1dd0 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-context-09.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-context-09.kt
@@ -6,10 +6,11 @@
package kotlinx.coroutines.guide.context09
import kotlinx.coroutines.*
-import kotlin.coroutines.*
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main() = runBlocking<Unit> {
+//sampleStart
launch(Dispatchers.Default + CoroutineName("test")) {
println("I'm working in thread ${Thread.currentThread().name}")
}
+//sampleEnd
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-context-10.kt b/core/kotlinx-coroutines-core/test/guide/example-context-10.kt
index 4f8b038..61b66c4 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-context-10.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-context-10.kt
@@ -5,8 +5,8 @@
// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
package kotlinx.coroutines.guide.context10
-import kotlinx.coroutines.*
import kotlin.coroutines.*
+import kotlinx.coroutines.*
class Activity : CoroutineScope {
lateinit var job: Job
@@ -37,7 +37,8 @@
}
} // class Activity ends
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main() = runBlocking<Unit> {
+//sampleStart
val activity = Activity()
activity.create() // create an activity
activity.doSomething() // run test function
@@ -46,4 +47,5 @@
println("Destroying activity!")
activity.destroy() // cancels all coroutines
delay(1000) // visually confirm that they don't work
+//sampleEnd
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-context-11.kt b/core/kotlinx-coroutines-core/test/guide/example-context-11.kt
index 24282b6..8de958e 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-context-11.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-context-11.kt
@@ -6,11 +6,11 @@
package kotlinx.coroutines.guide.context11
import kotlinx.coroutines.*
-import kotlin.coroutines.*
val threadLocal = ThreadLocal<String?>() // declare thread-local variable
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main() = runBlocking<Unit> {
+//sampleStart
threadLocal.set("main")
println("Pre-main, current thread: ${Thread.currentThread()}, thread local value: '${threadLocal.get()}'")
val job = launch(Dispatchers.Default + threadLocal.asContextElement(value = "launch")) {
@@ -20,4 +20,5 @@
}
job.join()
println("Post-main, current thread: ${Thread.currentThread()}, thread local value: '${threadLocal.get()}'")
+//sampleEnd
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-exceptions-01.kt b/core/kotlinx-coroutines-core/test/guide/example-exceptions-01.kt
index 3e72819..c931409 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-exceptions-01.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-exceptions-01.kt
@@ -7,7 +7,7 @@
import kotlinx.coroutines.*
-fun main(args: Array<String>) = runBlocking {
+fun main() = runBlocking {
val job = GlobalScope.launch {
println("Throwing exception from launch")
throw IndexOutOfBoundsException() // Will be printed to the console by Thread.defaultUncaughtExceptionHandler
diff --git a/core/kotlinx-coroutines-core/test/guide/example-exceptions-02.kt b/core/kotlinx-coroutines-core/test/guide/example-exceptions-02.kt
index b11d0bc..46f6dab 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-exceptions-02.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-exceptions-02.kt
@@ -7,7 +7,8 @@
import kotlinx.coroutines.*
-fun main(args: Array<String>) = runBlocking {
+fun main() = runBlocking {
+//sampleStart
val handler = CoroutineExceptionHandler { _, exception ->
println("Caught $exception")
}
@@ -18,4 +19,5 @@
throw ArithmeticException() // Nothing will be printed, relying on user to call deferred.await()
}
joinAll(job, deferred)
+//sampleEnd
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-exceptions-03.kt b/core/kotlinx-coroutines-core/test/guide/example-exceptions-03.kt
index a1f2c4b..1166519 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-exceptions-03.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-exceptions-03.kt
@@ -6,9 +6,9 @@
package kotlinx.coroutines.guide.exceptions03
import kotlinx.coroutines.*
-import kotlin.coroutines.*
-fun main(args: Array<String>) = runBlocking {
+fun main() = runBlocking {
+//sampleStart
val job = launch {
val child = launch {
try {
@@ -25,4 +25,5 @@
println("Parent is not cancelled")
}
job.join()
+//sampleEnd
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-exceptions-04.kt b/core/kotlinx-coroutines-core/test/guide/example-exceptions-04.kt
index 5db1e84..ab530fe 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-exceptions-04.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-exceptions-04.kt
@@ -6,9 +6,9 @@
package kotlinx.coroutines.guide.exceptions04
import kotlinx.coroutines.*
-import kotlin.coroutines.*
-fun main(args: Array<String>) = runBlocking {
+fun main() = runBlocking {
+//sampleEnd
val handler = CoroutineExceptionHandler { _, exception ->
println("Caught $exception")
}
@@ -31,4 +31,5 @@
}
}
job.join()
+//sampleEnd
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-exceptions-05.kt b/core/kotlinx-coroutines-core/test/guide/example-exceptions-05.kt
index 2f8a114..5271873 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-exceptions-05.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-exceptions-05.kt
@@ -5,12 +5,12 @@
// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
package kotlinx.coroutines.guide.exceptions05
-import kotlinx.coroutines.*
import kotlinx.coroutines.exceptions.*
-import kotlin.coroutines.*
+
+import kotlinx.coroutines.*
import java.io.*
-fun main(args: Array<String>) = runBlocking {
+fun main() = runBlocking {
val handler = CoroutineExceptionHandler { _, exception ->
println("Caught $exception with suppressed ${exception.suppressed.contentToString()}")
}
@@ -28,5 +28,5 @@
}
delay(Long.MAX_VALUE)
}
- job.join()
+ job.join()
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-exceptions-06.kt b/core/kotlinx-coroutines-core/test/guide/example-exceptions-06.kt
index 6566168..076a097 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-exceptions-06.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-exceptions-06.kt
@@ -6,10 +6,10 @@
package kotlinx.coroutines.guide.exceptions06
import kotlinx.coroutines.*
-import kotlin.coroutines.*
import java.io.*
-fun main(args: Array<String>) = runBlocking {
+fun main() = runBlocking {
+//sampleStart
val handler = CoroutineExceptionHandler { _, exception ->
println("Caught original $exception")
}
@@ -29,4 +29,5 @@
}
}
job.join()
+//sampleEnd
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-select-01.kt b/core/kotlinx-coroutines-core/test/guide/example-select-01.kt
index fd84c1d..f4cdd28 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-select-01.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-select-01.kt
@@ -36,7 +36,7 @@
}
}
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main() = runBlocking<Unit> {
val fizz = fizz()
val buzz = buzz()
repeat(7) {
diff --git a/core/kotlinx-coroutines-core/test/guide/example-select-02.kt b/core/kotlinx-coroutines-core/test/guide/example-select-02.kt
index 731fb68..ff7e5c6 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-select-02.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-select-02.kt
@@ -26,7 +26,7 @@
}
}
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main() = runBlocking<Unit> {
val a = produce<String> {
repeat(4) { send("Hello $it") }
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-select-03.kt b/core/kotlinx-coroutines-core/test/guide/example-select-03.kt
index 56fb09c..35ea2eb 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-select-03.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-select-03.kt
@@ -20,7 +20,7 @@
}
}
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main() = runBlocking<Unit> {
val side = Channel<Int>() // allocate side channel
launch { // this is a very fast consumer for the side channel
side.consumeEach { println("Side channel has $it") }
diff --git a/core/kotlinx-coroutines-core/test/guide/example-select-04.kt b/core/kotlinx-coroutines-core/test/guide/example-select-04.kt
index aacfe7c..3662741 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-select-04.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-select-04.kt
@@ -20,7 +20,7 @@
return List(12) { asyncString(random.nextInt(1000)) }
}
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main() = runBlocking<Unit> {
val list = asyncStringsList()
val result = select<String> {
list.withIndex().forEach { (index, deferred) ->
diff --git a/core/kotlinx-coroutines-core/test/guide/example-select-05.kt b/core/kotlinx-coroutines-core/test/guide/example-select-05.kt
index a13d040..f7a4b9f 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-select-05.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-select-05.kt
@@ -36,7 +36,7 @@
str
}
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main() = runBlocking<Unit> {
val chan = Channel<Deferred<String>>() // the channel for test
launch { // launch printing coroutine
for (s in switchMapDeferreds(chan))
diff --git a/core/kotlinx-coroutines-core/test/guide/example-supervision-01.kt b/core/kotlinx-coroutines-core/test/guide/example-supervision-01.kt
index 43a8c70..eac450a 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-supervision-01.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-supervision-01.kt
@@ -6,12 +6,11 @@
package kotlinx.coroutines.guide.supervision01
import kotlinx.coroutines.*
-import kotlin.coroutines.*
-fun main(args: Array<String>) = runBlocking {
+fun main() = runBlocking {
val supervisor = SupervisorJob()
with(CoroutineScope(coroutineContext + supervisor)) {
- // launch the first child -- its exception is ignored for this example (don't do this in practise!)
+ // launch the first child -- its exception is ignored for this example (don't do this in practice!)
val firstChild = launch(CoroutineExceptionHandler { _, _ -> }) {
println("First child is failing")
throw AssertionError("First child is cancelled")
diff --git a/core/kotlinx-coroutines-core/test/guide/example-supervision-02.kt b/core/kotlinx-coroutines-core/test/guide/example-supervision-02.kt
index 28490a4..47a3525 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-supervision-02.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-supervision-02.kt
@@ -5,10 +5,10 @@
// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
package kotlinx.coroutines.guide.supervision02
-import kotlinx.coroutines.*
import kotlin.coroutines.*
+import kotlinx.coroutines.*
-fun main(args: Array<String>) = runBlocking {
+fun main() = runBlocking {
try {
supervisorScope {
val child = launch {
diff --git a/core/kotlinx-coroutines-core/test/guide/example-supervision-03.kt b/core/kotlinx-coroutines-core/test/guide/example-supervision-03.kt
index a9f38a8..c50b263 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-supervision-03.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-supervision-03.kt
@@ -5,10 +5,10 @@
// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
package kotlinx.coroutines.guide.supervision03
-import kotlinx.coroutines.*
import kotlin.coroutines.*
+import kotlinx.coroutines.*
-fun main(args: Array<String>) = runBlocking {
+fun main() = runBlocking {
val handler = CoroutineExceptionHandler { _, exception ->
println("Caught $exception")
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-sync-01.kt b/core/kotlinx-coroutines-core/test/guide/example-sync-01.kt
index f7f4bbc..e380554 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-sync-01.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-sync-01.kt
@@ -25,7 +25,7 @@
var counter = 0
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main() = runBlocking<Unit> {
GlobalScope.massiveRun {
counter++
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-sync-01b.kt b/core/kotlinx-coroutines-core/test/guide/example-sync-01b.kt
index 119a291..b242f30 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-sync-01b.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-sync-01b.kt
@@ -26,7 +26,7 @@
val mtContext = newFixedThreadPoolContext(2, "mtPool") // explicitly define context with two threads
var counter = 0
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main() = runBlocking<Unit> {
CoroutineScope(mtContext).massiveRun { // use it instead of Dispatchers.Default in this sample and below
counter++
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-sync-02.kt b/core/kotlinx-coroutines-core/test/guide/example-sync-02.kt
index b338b17..b1c10d8 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-sync-02.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-sync-02.kt
@@ -26,7 +26,7 @@
@Volatile // in Kotlin `volatile` is an annotation
var counter = 0
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main() = runBlocking<Unit> {
GlobalScope.massiveRun {
counter++
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-sync-03.kt b/core/kotlinx-coroutines-core/test/guide/example-sync-03.kt
index bfedaa1..1eabc1b 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-sync-03.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-sync-03.kt
@@ -26,7 +26,7 @@
var counter = AtomicInteger()
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main() = runBlocking<Unit> {
GlobalScope.massiveRun {
counter.incrementAndGet()
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-sync-04.kt b/core/kotlinx-coroutines-core/test/guide/example-sync-04.kt
index b9dd90a..5d1fd88 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-sync-04.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-sync-04.kt
@@ -26,7 +26,7 @@
val counterContext = newSingleThreadContext("CounterContext")
var counter = 0
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main() = runBlocking<Unit> {
GlobalScope.massiveRun { // run each coroutine with DefaultDispathcer
withContext(counterContext) { // but confine each increment to the single-threaded context
counter++
diff --git a/core/kotlinx-coroutines-core/test/guide/example-sync-05.kt b/core/kotlinx-coroutines-core/test/guide/example-sync-05.kt
index bfe40a0..752c0e8 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-sync-05.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-sync-05.kt
@@ -26,7 +26,7 @@
val counterContext = newSingleThreadContext("CounterContext")
var counter = 0
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main() = runBlocking<Unit> {
CoroutineScope(counterContext).massiveRun { // run each coroutine in the single-threaded context
counter++
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-sync-06.kt b/core/kotlinx-coroutines-core/test/guide/example-sync-06.kt
index af54318..891533d 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-sync-06.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-sync-06.kt
@@ -27,7 +27,7 @@
val mutex = Mutex()
var counter = 0
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main() = runBlocking<Unit> {
GlobalScope.massiveRun {
mutex.withLock {
counter++
diff --git a/core/kotlinx-coroutines-core/test/guide/example-sync-07.kt b/core/kotlinx-coroutines-core/test/guide/example-sync-07.kt
index f781fc8..ccac26d 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-sync-07.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-sync-07.kt
@@ -40,7 +40,7 @@
}
}
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main() = runBlocking<Unit> {
val counter = counterActor() // create the actor
GlobalScope.massiveRun {
counter.send(IncCounter)
diff --git a/core/kotlinx-coroutines-core/test/guide/test/BasicsGuideTest.kt b/core/kotlinx-coroutines-core/test/guide/test/BasicsGuideTest.kt
index 9c11fbd..93b49a6 100644
--- a/core/kotlinx-coroutines-core/test/guide/test/BasicsGuideTest.kt
+++ b/core/kotlinx-coroutines-core/test/guide/test/BasicsGuideTest.kt
@@ -7,7 +7,7 @@
@Test
fun testKotlinxCoroutinesGuideBasic01() {
- test("KotlinxCoroutinesGuideBasic01") { kotlinx.coroutines.guide.basic01.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideBasic01") { kotlinx.coroutines.guide.basic01.main() }.verifyLines(
"Hello,",
"World!"
)
@@ -15,7 +15,7 @@
@Test
fun testKotlinxCoroutinesGuideBasic02() {
- test("KotlinxCoroutinesGuideBasic02") { kotlinx.coroutines.guide.basic02.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideBasic02") { kotlinx.coroutines.guide.basic02.main() }.verifyLines(
"Hello,",
"World!"
)
@@ -23,7 +23,7 @@
@Test
fun testKotlinxCoroutinesGuideBasic02b() {
- test("KotlinxCoroutinesGuideBasic02b") { kotlinx.coroutines.guide.basic02b.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideBasic02b") { kotlinx.coroutines.guide.basic02b.main() }.verifyLines(
"Hello,",
"World!"
)
@@ -31,7 +31,7 @@
@Test
fun testKotlinxCoroutinesGuideBasic03() {
- test("KotlinxCoroutinesGuideBasic03") { kotlinx.coroutines.guide.basic03.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideBasic03") { kotlinx.coroutines.guide.basic03.main() }.verifyLines(
"Hello,",
"World!"
)
@@ -39,7 +39,7 @@
@Test
fun testKotlinxCoroutinesGuideBasic03s() {
- test("KotlinxCoroutinesGuideBasic03s") { kotlinx.coroutines.guide.basic03s.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideBasic03s") { kotlinx.coroutines.guide.basic03s.main() }.verifyLines(
"Hello,",
"World!"
)
@@ -47,7 +47,7 @@
@Test
fun testKotlinxCoroutinesGuideBasic04() {
- test("KotlinxCoroutinesGuideBasic04") { kotlinx.coroutines.guide.basic04.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideBasic04") { kotlinx.coroutines.guide.basic04.main() }.verifyLines(
"Task from coroutine scope",
"Task from runBlocking",
"Task from nested launch",
@@ -57,7 +57,7 @@
@Test
fun testKotlinxCoroutinesGuideBasic05() {
- test("KotlinxCoroutinesGuideBasic05") { kotlinx.coroutines.guide.basic05.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideBasic05") { kotlinx.coroutines.guide.basic05.main() }.verifyLines(
"Hello,",
"World!"
)
@@ -65,14 +65,14 @@
@Test
fun testKotlinxCoroutinesGuideBasic06() {
- test("KotlinxCoroutinesGuideBasic06") { kotlinx.coroutines.guide.basic06.main(emptyArray()) }.also { lines ->
+ test("KotlinxCoroutinesGuideBasic06") { kotlinx.coroutines.guide.basic06.main() }.also { lines ->
check(lines.size == 1 && lines[0] == ".".repeat(100_000))
}
}
@Test
fun testKotlinxCoroutinesGuideBasic07() {
- test("KotlinxCoroutinesGuideBasic07") { kotlinx.coroutines.guide.basic07.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideBasic07") { kotlinx.coroutines.guide.basic07.main() }.verifyLines(
"I'm sleeping 0 ...",
"I'm sleeping 1 ...",
"I'm sleeping 2 ..."
diff --git a/core/kotlinx-coroutines-core/test/guide/test/CancellationTimeOutsGuideTest.kt b/core/kotlinx-coroutines-core/test/guide/test/CancellationTimeOutsGuideTest.kt
index 47f5e88..47cc262 100644
--- a/core/kotlinx-coroutines-core/test/guide/test/CancellationTimeOutsGuideTest.kt
+++ b/core/kotlinx-coroutines-core/test/guide/test/CancellationTimeOutsGuideTest.kt
@@ -7,7 +7,7 @@
@Test
fun testKotlinxCoroutinesGuideCancel01() {
- test("KotlinxCoroutinesGuideCancel01") { kotlinx.coroutines.guide.cancel01.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideCancel01") { kotlinx.coroutines.guide.cancel01.main() }.verifyLines(
"I'm sleeping 0 ...",
"I'm sleeping 1 ...",
"I'm sleeping 2 ...",
@@ -18,7 +18,7 @@
@Test
fun testKotlinxCoroutinesGuideCancel02() {
- test("KotlinxCoroutinesGuideCancel02") { kotlinx.coroutines.guide.cancel02.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideCancel02") { kotlinx.coroutines.guide.cancel02.main() }.verifyLines(
"I'm sleeping 0 ...",
"I'm sleeping 1 ...",
"I'm sleeping 2 ...",
@@ -31,7 +31,7 @@
@Test
fun testKotlinxCoroutinesGuideCancel03() {
- test("KotlinxCoroutinesGuideCancel03") { kotlinx.coroutines.guide.cancel03.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideCancel03") { kotlinx.coroutines.guide.cancel03.main() }.verifyLines(
"I'm sleeping 0 ...",
"I'm sleeping 1 ...",
"I'm sleeping 2 ...",
@@ -42,7 +42,7 @@
@Test
fun testKotlinxCoroutinesGuideCancel04() {
- test("KotlinxCoroutinesGuideCancel04") { kotlinx.coroutines.guide.cancel04.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideCancel04") { kotlinx.coroutines.guide.cancel04.main() }.verifyLines(
"I'm sleeping 0 ...",
"I'm sleeping 1 ...",
"I'm sleeping 2 ...",
@@ -54,7 +54,7 @@
@Test
fun testKotlinxCoroutinesGuideCancel05() {
- test("KotlinxCoroutinesGuideCancel05") { kotlinx.coroutines.guide.cancel05.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideCancel05") { kotlinx.coroutines.guide.cancel05.main() }.verifyLines(
"I'm sleeping 0 ...",
"I'm sleeping 1 ...",
"I'm sleeping 2 ...",
@@ -67,7 +67,7 @@
@Test
fun testKotlinxCoroutinesGuideCancel06() {
- test("KotlinxCoroutinesGuideCancel06") { kotlinx.coroutines.guide.cancel06.main(emptyArray()) }.verifyLinesStartWith(
+ test("KotlinxCoroutinesGuideCancel06") { kotlinx.coroutines.guide.cancel06.main() }.verifyLinesStartWith(
"I'm sleeping 0 ...",
"I'm sleeping 1 ...",
"I'm sleeping 2 ...",
@@ -77,7 +77,7 @@
@Test
fun testKotlinxCoroutinesGuideCancel07() {
- test("KotlinxCoroutinesGuideCancel07") { kotlinx.coroutines.guide.cancel07.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideCancel07") { kotlinx.coroutines.guide.cancel07.main() }.verifyLines(
"I'm sleeping 0 ...",
"I'm sleeping 1 ...",
"I'm sleeping 2 ...",
diff --git a/core/kotlinx-coroutines-core/test/guide/test/ChannelsGuideTest.kt b/core/kotlinx-coroutines-core/test/guide/test/ChannelsGuideTest.kt
index 5f6323c..a747c98 100644
--- a/core/kotlinx-coroutines-core/test/guide/test/ChannelsGuideTest.kt
+++ b/core/kotlinx-coroutines-core/test/guide/test/ChannelsGuideTest.kt
@@ -7,7 +7,7 @@
@Test
fun testKotlinxCoroutinesGuideChannel01() {
- test("KotlinxCoroutinesGuideChannel01") { kotlinx.coroutines.guide.channel01.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideChannel01") { kotlinx.coroutines.guide.channel01.main() }.verifyLines(
"1",
"4",
"9",
@@ -19,7 +19,7 @@
@Test
fun testKotlinxCoroutinesGuideChannel02() {
- test("KotlinxCoroutinesGuideChannel02") { kotlinx.coroutines.guide.channel02.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideChannel02") { kotlinx.coroutines.guide.channel02.main() }.verifyLines(
"1",
"4",
"9",
@@ -31,7 +31,7 @@
@Test
fun testKotlinxCoroutinesGuideChannel03() {
- test("KotlinxCoroutinesGuideChannel03") { kotlinx.coroutines.guide.channel03.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideChannel03") { kotlinx.coroutines.guide.channel03.main() }.verifyLines(
"1",
"4",
"9",
@@ -43,7 +43,7 @@
@Test
fun testKotlinxCoroutinesGuideChannel04() {
- test("KotlinxCoroutinesGuideChannel04") { kotlinx.coroutines.guide.channel04.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideChannel04") { kotlinx.coroutines.guide.channel04.main() }.verifyLines(
"1",
"4",
"9",
@@ -55,7 +55,7 @@
@Test
fun testKotlinxCoroutinesGuideChannel05() {
- test("KotlinxCoroutinesGuideChannel05") { kotlinx.coroutines.guide.channel05.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideChannel05") { kotlinx.coroutines.guide.channel05.main() }.verifyLines(
"2",
"3",
"5",
@@ -71,14 +71,14 @@
@Test
fun testKotlinxCoroutinesGuideChannel06() {
- test("KotlinxCoroutinesGuideChannel06") { kotlinx.coroutines.guide.channel06.main(emptyArray()) }.also { lines ->
+ test("KotlinxCoroutinesGuideChannel06") { kotlinx.coroutines.guide.channel06.main() }.also { lines ->
check(lines.size == 10 && lines.withIndex().all { (i, line) -> line.startsWith("Processor #") && line.endsWith(" received ${i + 1}") })
}
}
@Test
fun testKotlinxCoroutinesGuideChannel07() {
- test("KotlinxCoroutinesGuideChannel07") { kotlinx.coroutines.guide.channel07.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideChannel07") { kotlinx.coroutines.guide.channel07.main() }.verifyLines(
"foo",
"foo",
"BAR!",
@@ -90,7 +90,7 @@
@Test
fun testKotlinxCoroutinesGuideChannel08() {
- test("KotlinxCoroutinesGuideChannel08") { kotlinx.coroutines.guide.channel08.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideChannel08") { kotlinx.coroutines.guide.channel08.main() }.verifyLines(
"Sending 0",
"Sending 1",
"Sending 2",
@@ -101,7 +101,7 @@
@Test
fun testKotlinxCoroutinesGuideChannel09() {
- test("KotlinxCoroutinesGuideChannel09") { kotlinx.coroutines.guide.channel09.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideChannel09") { kotlinx.coroutines.guide.channel09.main() }.verifyLines(
"ping Ball(hits=1)",
"pong Ball(hits=2)",
"ping Ball(hits=3)",
@@ -111,7 +111,7 @@
@Test
fun testKotlinxCoroutinesGuideChannel10() {
- test("KotlinxCoroutinesGuideChannel10") { kotlinx.coroutines.guide.channel10.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideChannel10") { kotlinx.coroutines.guide.channel10.main() }.verifyLines(
"Initial element is available immediately: kotlin.Unit",
"Next element is not ready in 50 ms: null",
"Next element is ready in 100 ms: kotlin.Unit",
diff --git a/core/kotlinx-coroutines-core/test/guide/test/ComposingGuideTest.kt b/core/kotlinx-coroutines-core/test/guide/test/ComposingGuideTest.kt
index c44dbba..de4cba4 100644
--- a/core/kotlinx-coroutines-core/test/guide/test/ComposingGuideTest.kt
+++ b/core/kotlinx-coroutines-core/test/guide/test/ComposingGuideTest.kt
@@ -7,7 +7,7 @@
@Test
fun testKotlinxCoroutinesGuideCompose01() {
- test("KotlinxCoroutinesGuideCompose01") { kotlinx.coroutines.guide.compose01.main(emptyArray()) }.verifyLinesArbitraryTime(
+ test("KotlinxCoroutinesGuideCompose01") { kotlinx.coroutines.guide.compose01.main() }.verifyLinesArbitraryTime(
"The answer is 42",
"Completed in 2017 ms"
)
@@ -15,7 +15,7 @@
@Test
fun testKotlinxCoroutinesGuideCompose02() {
- test("KotlinxCoroutinesGuideCompose02") { kotlinx.coroutines.guide.compose02.main(emptyArray()) }.verifyLinesArbitraryTime(
+ test("KotlinxCoroutinesGuideCompose02") { kotlinx.coroutines.guide.compose02.main() }.verifyLinesArbitraryTime(
"The answer is 42",
"Completed in 1017 ms"
)
@@ -23,7 +23,7 @@
@Test
fun testKotlinxCoroutinesGuideCompose03() {
- test("KotlinxCoroutinesGuideCompose03") { kotlinx.coroutines.guide.compose03.main(emptyArray()) }.verifyLinesArbitraryTime(
+ test("KotlinxCoroutinesGuideCompose03") { kotlinx.coroutines.guide.compose03.main() }.verifyLinesArbitraryTime(
"The answer is 42",
"Completed in 1017 ms"
)
@@ -31,7 +31,7 @@
@Test
fun testKotlinxCoroutinesGuideCompose04() {
- test("KotlinxCoroutinesGuideCompose04") { kotlinx.coroutines.guide.compose04.main(emptyArray()) }.verifyLinesArbitraryTime(
+ test("KotlinxCoroutinesGuideCompose04") { kotlinx.coroutines.guide.compose04.main() }.verifyLinesArbitraryTime(
"The answer is 42",
"Completed in 1085 ms"
)
@@ -39,7 +39,7 @@
@Test
fun testKotlinxCoroutinesGuideCompose05() {
- test("KotlinxCoroutinesGuideCompose05") { kotlinx.coroutines.guide.compose05.main(emptyArray()) }.verifyLinesArbitraryTime(
+ test("KotlinxCoroutinesGuideCompose05") { kotlinx.coroutines.guide.compose05.main() }.verifyLinesArbitraryTime(
"The answer is 42",
"Completed in 1017 ms"
)
@@ -47,7 +47,7 @@
@Test
fun testKotlinxCoroutinesGuideCompose06() {
- test("KotlinxCoroutinesGuideCompose06") { kotlinx.coroutines.guide.compose06.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideCompose06") { kotlinx.coroutines.guide.compose06.main() }.verifyLines(
"Second child throws an exception",
"First child was cancelled",
"Computation failed with ArithmeticException"
diff --git a/core/kotlinx-coroutines-core/test/guide/test/DispatcherGuideTest.kt b/core/kotlinx-coroutines-core/test/guide/test/DispatcherGuideTest.kt
index 66d5b05..180738f 100644
--- a/core/kotlinx-coroutines-core/test/guide/test/DispatcherGuideTest.kt
+++ b/core/kotlinx-coroutines-core/test/guide/test/DispatcherGuideTest.kt
@@ -7,7 +7,7 @@
@Test
fun testKotlinxCoroutinesGuideContext01() {
- test("KotlinxCoroutinesGuideContext01") { kotlinx.coroutines.guide.context01.main(emptyArray()) }.verifyLinesStartUnordered(
+ test("KotlinxCoroutinesGuideContext01") { kotlinx.coroutines.guide.context01.main() }.verifyLinesStartUnordered(
"Unconfined : I'm working in thread main",
"Default : I'm working in thread DefaultDispatcher-worker-1",
"newSingleThreadContext: I'm working in thread MyOwnThread",
@@ -17,7 +17,7 @@
@Test
fun testKotlinxCoroutinesGuideContext02() {
- test("KotlinxCoroutinesGuideContext02") { kotlinx.coroutines.guide.context02.main(emptyArray()) }.verifyLinesStart(
+ test("KotlinxCoroutinesGuideContext02") { kotlinx.coroutines.guide.context02.main() }.verifyLinesStart(
"Unconfined : I'm working in thread main",
"main runBlocking: I'm working in thread main",
"Unconfined : After delay in thread kotlinx.coroutines.DefaultExecutor",
@@ -27,7 +27,7 @@
@Test
fun testKotlinxCoroutinesGuideContext03() {
- test("KotlinxCoroutinesGuideContext03") { kotlinx.coroutines.guide.context03.main(emptyArray()) }.verifyLinesFlexibleThread(
+ test("KotlinxCoroutinesGuideContext03") { kotlinx.coroutines.guide.context03.main() }.verifyLinesFlexibleThread(
"[main @coroutine#2] I'm computing a piece of the answer",
"[main @coroutine#3] I'm computing another piece of the answer",
"[main @coroutine#1] The answer is 42"
@@ -36,7 +36,7 @@
@Test
fun testKotlinxCoroutinesGuideContext04() {
- test("KotlinxCoroutinesGuideContext04") { kotlinx.coroutines.guide.context04.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideContext04") { kotlinx.coroutines.guide.context04.main() }.verifyLines(
"[Ctx1 @coroutine#1] Started in ctx1",
"[Ctx2 @coroutine#1] Working in ctx2",
"[Ctx1 @coroutine#1] Back to ctx1"
@@ -45,14 +45,14 @@
@Test
fun testKotlinxCoroutinesGuideContext05() {
- test("KotlinxCoroutinesGuideContext05") { kotlinx.coroutines.guide.context05.main(emptyArray()) }.also { lines ->
+ test("KotlinxCoroutinesGuideContext05") { kotlinx.coroutines.guide.context05.main() }.also { lines ->
check(lines.size == 1 && lines[0].startsWith("My job is \"coroutine#1\":BlockingCoroutine{Active}@"))
}
}
@Test
fun testKotlinxCoroutinesGuideContext06() {
- test("KotlinxCoroutinesGuideContext06") { kotlinx.coroutines.guide.context06.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideContext06") { kotlinx.coroutines.guide.context06.main() }.verifyLines(
"job1: I run in GlobalScope and execute independently!",
"job2: I am a child of the request coroutine",
"job1: I am not affected by cancellation of the request",
@@ -62,7 +62,7 @@
@Test
fun testKotlinxCoroutinesGuideContext07() {
- test("KotlinxCoroutinesGuideContext07") { kotlinx.coroutines.guide.context07.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideContext07") { kotlinx.coroutines.guide.context07.main() }.verifyLines(
"request: I'm done and I don't explicitly join my children that are still active",
"Coroutine 0 is done",
"Coroutine 1 is done",
@@ -73,7 +73,7 @@
@Test
fun testKotlinxCoroutinesGuideContext08() {
- test("KotlinxCoroutinesGuideContext08") { kotlinx.coroutines.guide.context08.main(emptyArray()) }.verifyLinesFlexibleThread(
+ test("KotlinxCoroutinesGuideContext08") { kotlinx.coroutines.guide.context08.main() }.verifyLinesFlexibleThread(
"[main @main#1] Started main coroutine",
"[main @v1coroutine#2] Computing v1",
"[main @v2coroutine#3] Computing v2",
@@ -83,14 +83,14 @@
@Test
fun testKotlinxCoroutinesGuideContext09() {
- test("KotlinxCoroutinesGuideContext09") { kotlinx.coroutines.guide.context09.main(emptyArray()) }.verifyLinesFlexibleThread(
+ test("KotlinxCoroutinesGuideContext09") { kotlinx.coroutines.guide.context09.main() }.verifyLinesFlexibleThread(
"I'm working in thread DefaultDispatcher-worker-1 @test#2"
)
}
@Test
fun testKotlinxCoroutinesGuideContext10() {
- test("KotlinxCoroutinesGuideContext10") { kotlinx.coroutines.guide.context10.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideContext10") { kotlinx.coroutines.guide.context10.main() }.verifyLines(
"Launched coroutines",
"Coroutine 0 is done",
"Coroutine 1 is done",
@@ -100,7 +100,7 @@
@Test
fun testKotlinxCoroutinesGuideContext11() {
- test("KotlinxCoroutinesGuideContext11") { kotlinx.coroutines.guide.context11.main(emptyArray()) }.verifyLinesFlexibleThread(
+ test("KotlinxCoroutinesGuideContext11") { kotlinx.coroutines.guide.context11.main() }.verifyLinesFlexibleThread(
"Pre-main, current thread: Thread[main @coroutine#1,5,main], thread local value: 'main'",
"Launch start, current thread: Thread[DefaultDispatcher-worker-1 @coroutine#2,5,main], thread local value: 'launch'",
"After yield, current thread: Thread[DefaultDispatcher-worker-2 @coroutine#2,5,main], thread local value: 'launch'",
diff --git a/core/kotlinx-coroutines-core/test/guide/test/ExceptionsGuideTest.kt b/core/kotlinx-coroutines-core/test/guide/test/ExceptionsGuideTest.kt
index 305d016..7fa692b 100644
--- a/core/kotlinx-coroutines-core/test/guide/test/ExceptionsGuideTest.kt
+++ b/core/kotlinx-coroutines-core/test/guide/test/ExceptionsGuideTest.kt
@@ -7,7 +7,7 @@
@Test
fun testKotlinxCoroutinesGuideExceptions01() {
- test("KotlinxCoroutinesGuideExceptions01") { kotlinx.coroutines.guide.exceptions01.main(emptyArray()) }.verifyExceptions(
+ test("KotlinxCoroutinesGuideExceptions01") { kotlinx.coroutines.guide.exceptions01.main() }.verifyExceptions(
"Throwing exception from launch",
"Exception in thread \"DefaultDispatcher-worker-2 @coroutine#2\" java.lang.IndexOutOfBoundsException",
"Joined failed job",
@@ -18,14 +18,14 @@
@Test
fun testKotlinxCoroutinesGuideExceptions02() {
- test("KotlinxCoroutinesGuideExceptions02") { kotlinx.coroutines.guide.exceptions02.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideExceptions02") { kotlinx.coroutines.guide.exceptions02.main() }.verifyLines(
"Caught java.lang.AssertionError"
)
}
@Test
fun testKotlinxCoroutinesGuideExceptions03() {
- test("KotlinxCoroutinesGuideExceptions03") { kotlinx.coroutines.guide.exceptions03.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideExceptions03") { kotlinx.coroutines.guide.exceptions03.main() }.verifyLines(
"Cancelling child",
"Child is cancelled",
"Parent is not cancelled"
@@ -34,7 +34,7 @@
@Test
fun testKotlinxCoroutinesGuideExceptions04() {
- test("KotlinxCoroutinesGuideExceptions04") { kotlinx.coroutines.guide.exceptions04.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideExceptions04") { kotlinx.coroutines.guide.exceptions04.main() }.verifyLines(
"Second child throws an exception",
"Children are cancelled, but exception is not handled until all children terminate",
"The first child finished its non cancellable block",
@@ -44,14 +44,14 @@
@Test
fun testKotlinxCoroutinesGuideExceptions05() {
- test("KotlinxCoroutinesGuideExceptions05") { kotlinx.coroutines.guide.exceptions05.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideExceptions05") { kotlinx.coroutines.guide.exceptions05.main() }.verifyLines(
"Caught java.io.IOException with suppressed [java.lang.ArithmeticException]"
)
}
@Test
fun testKotlinxCoroutinesGuideExceptions06() {
- test("KotlinxCoroutinesGuideExceptions06") { kotlinx.coroutines.guide.exceptions06.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideExceptions06") { kotlinx.coroutines.guide.exceptions06.main() }.verifyLines(
"Rethrowing CancellationException with original cause",
"Caught original java.io.IOException"
)
@@ -59,7 +59,7 @@
@Test
fun testKotlinxCoroutinesGuideSupervision01() {
- test("KotlinxCoroutinesGuideSupervision01") { kotlinx.coroutines.guide.supervision01.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideSupervision01") { kotlinx.coroutines.guide.supervision01.main() }.verifyLines(
"First child is failing",
"First child is cancelled: true, but second one is still active",
"Cancelling supervisor",
@@ -69,7 +69,7 @@
@Test
fun testKotlinxCoroutinesGuideSupervision02() {
- test("KotlinxCoroutinesGuideSupervision02") { kotlinx.coroutines.guide.supervision02.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideSupervision02") { kotlinx.coroutines.guide.supervision02.main() }.verifyLines(
"Child is sleeping",
"Throwing exception from scope",
"Child is cancelled",
@@ -79,7 +79,7 @@
@Test
fun testKotlinxCoroutinesGuideSupervision03() {
- test("KotlinxCoroutinesGuideSupervision03") { kotlinx.coroutines.guide.supervision03.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideSupervision03") { kotlinx.coroutines.guide.supervision03.main() }.verifyLines(
"Scope is completing",
"Child throws an exception",
"Caught java.lang.AssertionError",
diff --git a/core/kotlinx-coroutines-core/test/guide/test/SelectGuideTest.kt b/core/kotlinx-coroutines-core/test/guide/test/SelectGuideTest.kt
index 990b87e..b5246ff 100644
--- a/core/kotlinx-coroutines-core/test/guide/test/SelectGuideTest.kt
+++ b/core/kotlinx-coroutines-core/test/guide/test/SelectGuideTest.kt
@@ -7,7 +7,7 @@
@Test
fun testKotlinxCoroutinesGuideSelect01() {
- test("KotlinxCoroutinesGuideSelect01") { kotlinx.coroutines.guide.select01.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideSelect01") { kotlinx.coroutines.guide.select01.main() }.verifyLines(
"fizz -> 'Fizz'",
"buzz -> 'Buzz!'",
"fizz -> 'Fizz'",
@@ -20,7 +20,7 @@
@Test
fun testKotlinxCoroutinesGuideSelect02() {
- test("KotlinxCoroutinesGuideSelect02") { kotlinx.coroutines.guide.select02.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideSelect02") { kotlinx.coroutines.guide.select02.main() }.verifyLines(
"a -> 'Hello 0'",
"a -> 'Hello 1'",
"b -> 'World 0'",
@@ -34,7 +34,7 @@
@Test
fun testKotlinxCoroutinesGuideSelect03() {
- test("KotlinxCoroutinesGuideSelect03") { kotlinx.coroutines.guide.select03.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideSelect03") { kotlinx.coroutines.guide.select03.main() }.verifyLines(
"Consuming 1",
"Side channel has 2",
"Side channel has 3",
@@ -51,7 +51,7 @@
@Test
fun testKotlinxCoroutinesGuideSelect04() {
- test("KotlinxCoroutinesGuideSelect04") { kotlinx.coroutines.guide.select04.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideSelect04") { kotlinx.coroutines.guide.select04.main() }.verifyLines(
"Deferred 4 produced answer 'Waited for 128 ms'",
"11 coroutines are still active"
)
@@ -59,7 +59,7 @@
@Test
fun testKotlinxCoroutinesGuideSelect05() {
- test("KotlinxCoroutinesGuideSelect05") { kotlinx.coroutines.guide.select05.main(emptyArray()) }.verifyLines(
+ test("KotlinxCoroutinesGuideSelect05") { kotlinx.coroutines.guide.select05.main() }.verifyLines(
"BEGIN",
"Replace",
"END",
diff --git a/core/kotlinx-coroutines-core/test/guide/test/SharedStateGuideTest.kt b/core/kotlinx-coroutines-core/test/guide/test/SharedStateGuideTest.kt
index a18da1e..b57dcfd 100644
--- a/core/kotlinx-coroutines-core/test/guide/test/SharedStateGuideTest.kt
+++ b/core/kotlinx-coroutines-core/test/guide/test/SharedStateGuideTest.kt
@@ -7,7 +7,7 @@
@Test
fun testKotlinxCoroutinesGuideSync01() {
- test("KotlinxCoroutinesGuideSync01") { kotlinx.coroutines.guide.sync01.main(emptyArray()) }.verifyLinesStart(
+ test("KotlinxCoroutinesGuideSync01") { kotlinx.coroutines.guide.sync01.main() }.verifyLinesStart(
"Completed 100000 actions in",
"Counter ="
)
@@ -15,7 +15,7 @@
@Test
fun testKotlinxCoroutinesGuideSync01b() {
- test("KotlinxCoroutinesGuideSync01b") { kotlinx.coroutines.guide.sync01b.main(emptyArray()) }.verifyLinesStart(
+ test("KotlinxCoroutinesGuideSync01b") { kotlinx.coroutines.guide.sync01b.main() }.verifyLinesStart(
"Completed 100000 actions in",
"Counter ="
)
@@ -23,7 +23,7 @@
@Test
fun testKotlinxCoroutinesGuideSync02() {
- test("KotlinxCoroutinesGuideSync02") { kotlinx.coroutines.guide.sync02.main(emptyArray()) }.verifyLinesStart(
+ test("KotlinxCoroutinesGuideSync02") { kotlinx.coroutines.guide.sync02.main() }.verifyLinesStart(
"Completed 100000 actions in",
"Counter ="
)
@@ -31,7 +31,7 @@
@Test
fun testKotlinxCoroutinesGuideSync03() {
- test("KotlinxCoroutinesGuideSync03") { kotlinx.coroutines.guide.sync03.main(emptyArray()) }.verifyLinesArbitraryTime(
+ test("KotlinxCoroutinesGuideSync03") { kotlinx.coroutines.guide.sync03.main() }.verifyLinesArbitraryTime(
"Completed 100000 actions in xxx ms",
"Counter = 100000"
)
@@ -39,7 +39,7 @@
@Test
fun testKotlinxCoroutinesGuideSync04() {
- test("KotlinxCoroutinesGuideSync04") { kotlinx.coroutines.guide.sync04.main(emptyArray()) }.verifyLinesArbitraryTime(
+ test("KotlinxCoroutinesGuideSync04") { kotlinx.coroutines.guide.sync04.main() }.verifyLinesArbitraryTime(
"Completed 100000 actions in xxx ms",
"Counter = 100000"
)
@@ -47,7 +47,7 @@
@Test
fun testKotlinxCoroutinesGuideSync05() {
- test("KotlinxCoroutinesGuideSync05") { kotlinx.coroutines.guide.sync05.main(emptyArray()) }.verifyLinesArbitraryTime(
+ test("KotlinxCoroutinesGuideSync05") { kotlinx.coroutines.guide.sync05.main() }.verifyLinesArbitraryTime(
"Completed 100000 actions in xxx ms",
"Counter = 100000"
)
@@ -55,7 +55,7 @@
@Test
fun testKotlinxCoroutinesGuideSync06() {
- test("KotlinxCoroutinesGuideSync06") { kotlinx.coroutines.guide.sync06.main(emptyArray()) }.verifyLinesArbitraryTime(
+ test("KotlinxCoroutinesGuideSync06") { kotlinx.coroutines.guide.sync06.main() }.verifyLinesArbitraryTime(
"Completed 100000 actions in xxx ms",
"Counter = 100000"
)
@@ -63,7 +63,7 @@
@Test
fun testKotlinxCoroutinesGuideSync07() {
- test("KotlinxCoroutinesGuideSync07") { kotlinx.coroutines.guide.sync07.main(emptyArray()) }.verifyLinesArbitraryTime(
+ test("KotlinxCoroutinesGuideSync07") { kotlinx.coroutines.guide.sync07.main() }.verifyLinesArbitraryTime(
"Completed 100000 actions in xxx ms",
"Counter = 100000"
)