blob: 7cbfb21d9ace4371909b07da4aea42b3103b3d06 [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.example08
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>) = runBlocking(CoroutineName("main")) {
25 log("Started main coroutine")
26 // run two background value computations
Roman Elizarov32d95322017-02-09 15:57:31 +030027 val v1 = async(CommonPool + CoroutineName("v1coroutine")) {
Roman Elizarov2f6d7c92017-02-03 15:16:07 +030028 log("Computing v1")
29 delay(500)
30 252
31 }
Roman Elizarov32d95322017-02-09 15:57:31 +030032 val v2 = async(CommonPool + CoroutineName("v2coroutine")) {
Roman Elizarov2f6d7c92017-02-03 15:16:07 +030033 log("Computing v2")
34 delay(1000)
35 6
36 }
37 log("The answer for v1 / v2 = ${v1.await() / v2.await()}")
38}