blob: 6a40e9bb8ac40c023e74ea5e097b1fd93b7465f7 [file] [log] [blame]
Roman Elizarovf16fd272017-02-07 11:26:00 +03001/*
2 * Copyright 2016-2017 JetBrains s.r.o.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Roman Elizarov2f6d7c92017-02-03 15:16:07 +030017// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
Roman Elizarovd0021622017-03-10 15:43:38 +030018package guide.context.example02
Roman Elizarov2f6d7c92017-02-03 15:16:07 +030019
20import kotlinx.coroutines.experimental.*
21
22fun main(args: Array<String>) = runBlocking<Unit> {
23 val jobs = arrayListOf<Job>()
24 jobs += launch(Unconfined) { // not confined -- will work with main thread
25 println(" 'Unconfined': I'm working in thread ${Thread.currentThread().name}")
Roman Elizarovd0021622017-03-10 15:43:38 +030026 delay(500)
Roman Elizarov2f6d7c92017-02-03 15:16:07 +030027 println(" 'Unconfined': After delay in thread ${Thread.currentThread().name}")
28 }
29 jobs += launch(context) { // context of the parent, runBlocking coroutine
30 println(" 'context': I'm working in thread ${Thread.currentThread().name}")
31 delay(1000)
32 println(" 'context': After delay in thread ${Thread.currentThread().name}")
33 }
34 jobs.forEach { it.join() }
35}