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 | cd3cb31 | 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.exampleBasic01 |
Roman Elizarov | 55a47f9 | 2017-01-24 10:21:31 +0300 | [diff] [blame] | 7 | |
Roman Elizarov | 0950dfa | 2018-07-13 10:33:25 +0300 | [diff] [blame] | 8 | import kotlinx.coroutines.* |
Roman Elizarov | 55a47f9 | 2017-01-24 10:21:31 +0300 | [diff] [blame] | 9 | |
Prendota | 65e6c8c | 2018-10-17 11:51:08 +0300 | [diff] [blame] | 10 | fun main() { |
Inego | 69c26df | 2019-04-21 14:51:25 +0700 | [diff] [blame] | 11 | GlobalScope.launch { // launch a new coroutine in background and continue |
Roman Elizarov | 7cf452e | 2017-01-29 21:58:33 +0300 | [diff] [blame] | 12 | delay(1000L) // non-blocking delay for 1 second (default time unit is ms) |
Roman Elizarov | 92ef15b | 2017-01-24 12:01:13 +0300 | [diff] [blame] | 13 | println("World!") // print after delay |
Roman Elizarov | 55a47f9 | 2017-01-24 10:21:31 +0300 | [diff] [blame] | 14 | } |
Roman Elizarov | a4d45d2 | 2017-11-20 16:47:09 +0300 | [diff] [blame] | 15 | println("Hello,") // main thread continues while coroutine is delayed |
Roman Elizarov | 7cf452e | 2017-01-29 21:58:33 +0300 | [diff] [blame] | 16 | Thread.sleep(2000L) // block main thread for 2 seconds to keep JVM alive |
Roman Elizarov | 92ef15b | 2017-01-24 12:01:13 +0300 | [diff] [blame] | 17 | } |