Kotlin coroutine async with delay
05:42 08 Aug 2018

I'm wrapping my head around the coroutine concept in Kotlin/Android. So, as I do not want to use Timertask, Handler with a post delayed I want to use coroutines to execute an async coroutine after a certain delay. I have the following semi-code:

 launch(UI) {
    val result = async(CommonPool) { 
        delay(30000)
        executeMethodAfterDelay() 
    }

    result.await()
 }

The problem with this is that actually in the async is both method's (delay and executeMethodAfterDelay) are executed at the same time. While I was expecting that first 30 seconds of delay would be introduced before executeMethodAfterDelay() would be fired. So my question is, how can I achieve this?

android kotlin coroutine kotlin-coroutines