blob: 0c20fc85d45e58497fb7333b28f1c0ae67fc3b13 [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 Elizarovfa7723e2017-02-06 11:17:51 +030018package guide.context.example04
Roman Elizarov2f6d7c92017-02-03 15:16:07 +030019
20import kotlinx.coroutines.experimental.*
21
22fun log(msg: String) = println("[${Thread.currentThread().name}] $msg")
23
24fun main(args: Array<String>) {
Roman Elizarovd9ae2bc2017-10-20 17:36:56 +080025 newSingleThreadContext("Ctx1").use { ctx1 ->
26 newSingleThreadContext("Ctx2").use { ctx2 ->
27 runBlocking(ctx1) {
28 log("Started in ctx1")
Roman Elizarovf9e13f52017-12-21 12:23:15 +030029 withContext(ctx2) {
Roman Elizarovd9ae2bc2017-10-20 17:36:56 +080030 log("Working in ctx2")
31 }
32 log("Back to ctx1")
33 }
Roman Elizarov2f6d7c92017-02-03 15:16:07 +030034 }
Roman Elizarov2f6d7c92017-02-03 15:16:07 +030035 }
36}