Roman Elizarov | f16fd27 | 2017-02-07 11:26:00 +0300 | [diff] [blame] | 1 | /* |
Roman Elizarov | 660c2d7 | 2020-02-14 13:18:37 +0300 | [diff] [blame] | 2 | * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. |
Roman Elizarov | f16fd27 | 2017-02-07 11:26:00 +0300 | [diff] [blame] | 3 | */ |
| 4 | |
Aurimas Liutikas | af4ee62 | 2021-05-12 21:56:16 +0000 | [diff] [blame^] | 5 | // This file was automatically generated from basics.md by Knit tool. Do not edit. |
Roman Elizarov | 660c2d7 | 2020-02-14 13:18:37 +0300 | [diff] [blame] | 6 | package kotlinx.coroutines.guide.exampleBasic06 |
Roman Elizarov | b3d55a5 | 2017-02-03 12:47:21 +0300 | [diff] [blame] | 7 | |
Roman Elizarov | 0950dfa | 2018-07-13 10:33:25 +0300 | [diff] [blame] | 8 | import kotlinx.coroutines.* |
Roman Elizarov | b3d55a5 | 2017-02-03 12:47:21 +0300 | [diff] [blame] | 9 | |
Roman Elizarov | 660c2d7 | 2020-02-14 13:18:37 +0300 | [diff] [blame] | 10 | fun main() = runBlocking { // this: CoroutineScope |
| 11 | launch { |
| 12 | delay(200L) |
| 13 | println("Task from runBlocking") |
Roman Elizarov | b3d55a5 | 2017-02-03 12:47:21 +0300 | [diff] [blame] | 14 | } |
Roman Elizarov | 660c2d7 | 2020-02-14 13:18:37 +0300 | [diff] [blame] | 15 | |
| 16 | coroutineScope { // Creates a coroutine scope |
| 17 | launch { |
| 18 | delay(500L) |
| 19 | println("Task from nested launch") |
| 20 | } |
| 21 | |
| 22 | delay(100L) |
| 23 | println("Task from coroutine scope") // This line will be printed before the nested launch |
| 24 | } |
| 25 | |
| 26 | println("Coroutine scope is over") // This line is not printed until the nested launch completes |
Roman Elizarov | b3d55a5 | 2017-02-03 12:47:21 +0300 | [diff] [blame] | 27 | } |