Skip to content

Commit 46935cb

Browse files
committed
Fix code sample for log()
Run on java9(9.0.4) The log(msg: String) doesn't work like the description in document. `fun log(msg: String) = println("[${Thread.currentThread().name}] $msg")` The output is not same like expected in document: ``` [main] Unconfined [ForkJoinPool.commonPool-worker-2] Default [main] main runBlocking [MyOwnThread] newSingleThreadContext [kotlinx.coroutines.DefaultExecutor] Unconfined ``` I change to: `fun log(msg: String) = Thread.currentThread().run { println("[$name @coroutine#$id] $msg") }` output: ``` [main @coroutineKotlin#1] Unconfined [ForkJoinPool.commonPool-worker-2 @coroutineKotlin#15] Default [main @coroutineKotlin#1] main runBlocking [MyOwnThread @coroutineKotlin#17] newSingleThreadContext [kotlinx.coroutines.DefaultExecutor @coroutineKotlin#13] Unconfined ```
1 parent 52d2f93 commit 46935cb

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

coroutines-guide.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ import kotlin.coroutines.experimental.*
11291129
-->
11301130

11311131
```kotlin
1132-
fun log(msg: String) = println("[${Thread.currentThread().name}] $msg")
1132+
fun log(msg: String) = Thread.currentThread().run { println("[$name @coroutine#$id] $msg") }
11331133

11341134
fun main(args: Array<String>) = runBlocking<Unit> {
11351135
val a = async {

0 commit comments

Comments
 (0)