xref: /aosp_15_r20/external/kotlinx.coroutines/kotlinx-coroutines-debug/test/RecoveryExample.kt (revision 7a7160fed73afa6648ef8aa100d4a336fe921d9a)
1 @file:Suppress("PackageDirectoryMismatch")
2 package example
3 
4 import kotlinx.coroutines.*
5 
<lambda>null6 object PublicApiImplementation : CoroutineScope by CoroutineScope(CoroutineName("Example")) {
7 
8     private fun doWork(): Int {
9         error("Internal invariant failed")
10     }
11 
12     private fun asynchronousWork(): Int {
13         return doWork() + 1
14     }
15 
16     public suspend fun awaitAsynchronousWorkInMainThread() {
17         val task = async(Dispatchers.Default) {
18             asynchronousWork()
19         }
20 
21         task.await()
22     }
23 }
24 
mainnull25 suspend fun main() {
26     // Try to switch debug mode on and off to see the difference
27     PublicApiImplementation.awaitAsynchronousWorkInMainThread()
28 }
29