aboutsummaryrefslogtreecommitdiffstats
path: root/kotlinx-coroutines-core/jvm/test/guide/example-supervision-01.kt
diff options
context:
space:
mode:
authorVsevolod Tolstopyatov <qwwdfsad@gmail.com>2019-01-28 11:34:24 +0300
committerGitHub <noreply@github.com>2019-01-28 11:34:24 +0300
commite50a0fa78aae052e128e8b17666e081e4dfc78be (patch)
treeca42bb4debc2851b3d282a9aeb1143860ebcf06e /kotlinx-coroutines-core/jvm/test/guide/example-supervision-01.kt
parent042b209f8017cadd6d9c1c868d798a282d9b8662 (diff)
downloadplatform_external_kotlinx.coroutines-e50a0fa78aae052e128e8b17666e081e4dfc78be.tar.gz
platform_external_kotlinx.coroutines-e50a0fa78aae052e128e8b17666e081e4dfc78be.tar.bz2
platform_external_kotlinx.coroutines-e50a0fa78aae052e128e8b17666e081e4dfc78be.zip
Migration to new multiplatorm plugin (#947)
Migration to a new multiplatform plugin * kotlinx-coroutines-core-[common|js|native] are merged into one core module with multiple source sets * Folder structure and readme are restructured * Publication process is patched to preserve backward compatibility with artifact names
Diffstat (limited to 'kotlinx-coroutines-core/jvm/test/guide/example-supervision-01.kt')
-rw-r--r--kotlinx-coroutines-core/jvm/test/guide/example-supervision-01.kt36
1 files changed, 36 insertions, 0 deletions
diff --git a/kotlinx-coroutines-core/jvm/test/guide/example-supervision-01.kt b/kotlinx-coroutines-core/jvm/test/guide/example-supervision-01.kt
new file mode 100644
index 00000000..eac450a7
--- /dev/null
+++ b/kotlinx-coroutines-core/jvm/test/guide/example-supervision-01.kt
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
+ */
+
+// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
+package kotlinx.coroutines.guide.supervision01
+
+import kotlinx.coroutines.*
+
+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 practice!)
+ val firstChild = launch(CoroutineExceptionHandler { _, _ -> }) {
+ println("First child is failing")
+ throw AssertionError("First child is cancelled")
+ }
+ // launch the second child
+ val secondChild = launch {
+ firstChild.join()
+ // Cancellation of the first child is not propagated to the second child
+ println("First child is cancelled: ${firstChild.isCancelled}, but second one is still active")
+ try {
+ delay(Long.MAX_VALUE)
+ } finally {
+ // But cancellation of the supervisor is propagated
+ println("Second child is cancelled because supervisor is cancelled")
+ }
+ }
+ // wait until the first child fails & completes
+ firstChild.join()
+ println("Cancelling supervisor")
+ supervisor.cancel()
+ secondChild.join()
+ }
+}