kotlin-examples icon indicating copy to clipboard operation
kotlin-examples copied to clipboard

Is there any way to skip delays and execute an ongoing Job

Open vikasacharya16 opened this issue 4 years ago • 0 comments

I have a Job like below

job = GlobalScope.launch {
    delay(5000)
    runOnUiThread {
        some unwanted code
    }
}

This job will wait for 5 seconds to execute. And to cancel it before 5 seconds I'm calling

job?.cancel()

Now, Is there a way to execute this job before 5 seconds have reached ?

I'm looking for something like job?.forceExecute.ignoreDelays or job?.forceExecute.ignoreDelay("FirstDelay") if there is a option for name like delay(5000,"FirstDelay")

That would be so helpful for me to avoid boiler plate code.

vikasacharya16 avatar Nov 16 '20 12:11 vikasacharya16