This file contains 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
interface Software { | |
fun getLicense(): String | |
} |
This file contains 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() = runBlocking { | |
launch(CoroutineName("parent")) { | |
launch { | |
println("coroutine1 started") | |
delay(500) | |
throw RuntimeException() | |
} | |
launch { |
This file contains 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() = runBlocking { | |
val job = launch { | |
println("Coroutine started.") | |
try { | |
delay(Long.MAX_VALUE) | |
} catch (ex: CancellationException) { | |
println("Coroutine cancelled.") | |
} |
This file contains 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.Dispatchers | |
import kotlinx.coroutines.delay | |
import kotlinx.coroutines.launch | |
import kotlinx.coroutines.runBlocking | |
fun main() = runBlocking { | |
launch(Dispatchers.Unconfined) { | |
println("Before delay. Thread name: ${Thread.currentThread().name}") | |
delay(500) | |
println("After delay. Thread name: ${Thread.currentThread().name}") |
This file contains 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 kotlin.concurrent.thread | |
fun main() { | |
repeat(100_000) { | |
thread { | |
Thread.sleep(1000L) | |
println(".") | |
} | |
} | |
} |
This file contains 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
fun main() = runBlocking { | |
val job = launch(CoroutineName("parent")) { | |
println("Launching two coroutines...") | |
val child1Job = launch { | |
println("coroutine1: I'm started") | |
delay(2000) | |
println("coroutine1: I'm done") | |
} | |
launch { | |
println("coroutine2: I'm started") |
This file contains 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
fun main() = runBlocking { | |
val job = launch(CoroutineName("parent")) { | |
launch { | |
delay(2000) | |
println("coroutine1: I'm done") | |
} | |
launch { | |
delay(3000) | |
println("coroutine2: I'm done") | |
} |
This file contains 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() = runBlocking { | |
val startTime = System.currentTimeMillis() | |
val job = launch(Dispatchers.Default) { | |
var nextPrintTime = startTime | |
var i = 0 | |
while (i < 5 && isActive) { // <-- HERE! | |
if (System.currentTimeMillis() >= nextPrintTime) { | |
println("job: I'm sleeping ${i++} ...") |
This file contains 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() = runBlocking { | |
val startTime = System.currentTimeMillis() | |
val job = launch(Dispatchers.Default) { | |
var nextPrintTime = startTime | |
var i = 0 | |
while (i < 5) { | |
if (System.currentTimeMillis() >= nextPrintTime) { | |
println("job: I'm sleeping ${i++} ...") |
This file contains 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.CoroutineName | |
import kotlinx.coroutines.delay | |
import kotlinx.coroutines.launch | |
import kotlinx.coroutines.runBlocking | |
fun main() = runBlocking { | |
val request = launch(CoroutineName("request")) { | |
repeat(3) { i -> | |
launch { | |
delay((i + 1) * 200L) // variable delay 200ms, 400ms, 600ms |