1 /* 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") 5 package example 6 7 import kotlinx.coroutines.* 8 <lambda>null9object 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 mainnull28suspend fun main() { 29 // Try to switch debug mode on and off to see the difference 30 PublicApiImplementation.awaitAsynchronousWorkInMainThread() 31 } 32