This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import kotlinx.coroutines.* | |
| fun main(args: Array<String>) { | |
| println("start") | |
| runBlocking { | |
| launch { | |
| println("main runBlocking: Current thread name: ${Thread.currentThread().name}") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import kotlinx.coroutines.* | |
| fun main(args: Array<String>) { | |
| println("start") | |
| val deferredResult: Deferred<String> = GlobalScope.async { | |
| delay(1000L) | |
| "Dacape.dev" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import kotlinx.coroutines.GlobalScope | |
| import kotlinx.coroutines.delay | |
| import kotlinx.coroutines.launch | |
| import kotlinx.coroutines.runBlocking | |
| fun main(args: Array<String>) { | |
| println("start") | |
| GlobalScope.launch { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import kotlinx.coroutines.delay | |
| import kotlinx.coroutines.runBlocking | |
| fun main(args: Array<String>) { | |
| println("start") | |
| runBlocking { | |
| println("before delay.") | |
| delay(1000) | |
| println("after delay.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import kotlinx.coroutines.* | |
| fun main(args: Array<String>) = runBlocking { | |
| val coroutine1=async { delay1() } | |
| val coroutine2=async { delay2() } | |
| println(coroutine1.await()+coroutine2.await()) | |
| } | |
| suspend fun delay1(): String { | |
| delay(3000) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import kotlinx.coroutines.* | |
| fun main(args: Array<String>) = runBlocking { | |
| var text1 = delay1() | |
| println(text1) | |
| var text2 = delay2() | |
| println(text2) | |
| } | |
| suspend fun delay1(): String { |