blob: 2280dd169442984e401b5cea4c4bc0881aa49553 [file] [log] [blame]
Vsevolod Tolstopyatovf5288982019-02-18 14:46:58 +03001/*
2 * Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3 */
4@file:Suppress("PackageDirectoryMismatch")
5package example
6
7import kotlinx.coroutines.*
8
9object PublicApiImplementation : CoroutineScope by CoroutineScope(CoroutineName("Example")) {
10
11 private fun doWork(): Int {
12 error("Internal invariant failed")
13 }
14
15 private fun asynchronousWork(): Int {
16 return doWork() + 1
17 }
18
19 public suspend fun awaitAsynchronousWorkInMainThread() {
20 val task = async(Dispatchers.Default) {
21 asynchronousWork()
22 }
23
24 task.await()
25 }
26}
27
28suspend fun main() {
29 // Try to switch debug mode on and off to see the difference
30 PublicApiImplementation.awaitAsynchronousWorkInMainThread()
31}