blob: 1620dc24f7fca87b14ea9071ce35df9c62b8e73c [file] [log] [blame]
Roman Elizarov2fd7cb32017-02-11 23:18:59 +03001/*
Roman Elizarov1f74a2d2018-06-29 19:19:45 +03002 * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
Roman Elizarov2fd7cb32017-02-11 23:18:59 +03003 */
4
5// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
Roman Elizarova9687a32018-06-29 17:28:38 +03006package kotlinx.coroutines.experimental.guide.context09
Roman Elizarov2fd7cb32017-02-11 23:18:59 +03007
Roman Elizarov96695782017-10-01 10:48:15 -07008import kotlinx.coroutines.experimental.*
Roman Elizarov2fd7cb32017-02-11 23:18:59 +03009
Roman Elizarov8b38fa22017-09-27 17:44:31 +030010fun log(msg: String) = println("[${Thread.currentThread().name}] $msg")
11
12fun main(args: Array<String>) = runBlocking(CoroutineName("main")) {
13 log("Started main coroutine")
14 // run two background value computations
Roman Elizarov66f018c2017-09-29 21:39:03 +030015 val v1 = async(CoroutineName("v1coroutine")) {
Roman Elizarov8b38fa22017-09-27 17:44:31 +030016 delay(500)
Roman Elizarov674efea2017-10-21 17:16:30 +030017 log("Computing v1")
Roman Elizarov8b38fa22017-09-27 17:44:31 +030018 252
Roman Elizarov2fd7cb32017-02-11 23:18:59 +030019 }
Roman Elizarov66f018c2017-09-29 21:39:03 +030020 val v2 = async(CoroutineName("v2coroutine")) {
Roman Elizarov8b38fa22017-09-27 17:44:31 +030021 delay(1000)
Roman Elizarov674efea2017-10-21 17:16:30 +030022 log("Computing v2")
Roman Elizarov8b38fa22017-09-27 17:44:31 +030023 6
24 }
25 log("The answer for v1 / v2 = ${v1.await() / v2.await()}")
Roman Elizarov2fd7cb32017-02-11 23:18:59 +030026}