forked from Kotlin/kotlinx.coroutines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RecoveryExample.kt
31 lines (24 loc) · 786 Bytes
/
RecoveryExample.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
* Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
@file:Suppress("PackageDirectoryMismatch")
package example
import kotlinx.coroutines.*
object PublicApiImplementation : CoroutineScope by CoroutineScope(CoroutineName("Example")) {
private fun doWork(): Int {
error("Internal invariant failed")
}
private fun asynchronousWork(): Int {
return doWork() + 1
}
public suspend fun awaitAsynchronousWorkInMainThread() {
val task = async(Dispatchers.Default) {
asynchronousWork()
}
task.await()
}
}
suspend fun main() {
// Try to switch debug mode on and off to see the difference
PublicApiImplementation.awaitAsynchronousWorkInMainThread()
}