https://kotlinlang.org logo
#coroutines
Title
# coroutines
u

uli

04/04/2017, 6:53 AM
@Ian Here comes the code. You provide inBackground(), main demonstrates how your users should apply it:
Copy code
fun inBackground(doWork: suspend () -> Unit) {
    launch(CommonPool) {
        try {
            doWork()
        } catch (t: Throwable) {
            // Do Logging, rethrow, ...
        }
    }
}

fun main(args: Array<String>) {
    inBackground {
        println("before delay")
        delay(100)
        println("after delay")
    }
    Thread.sleep(100000)
}
Ideally, inBackground() should be inline. But that is not yet supported.
👍 3
i

Ian

04/04/2017, 3:58 PM
Thank you Uli! I have moved this code into my codebase and will be testing it.
2 Views