CoroutineAsyncTask icon indicating copy to clipboard operation
CoroutineAsyncTask copied to clipboard

Kotlin Coroutine is not cancelled

Open JkMulti opened this issue 4 years ago • 3 comments
trafficstars

Hi, first of all a very big thanks for async task alternative. The code has one exception, it is not cancelling the coroutine/job when cancel is called. fun cancel(mayInterruptIfRunning: Boolean) { if (preJob == null || bgJob == null) { printLog("$taskName has already been cancelled/finished/not yet started.") return } if (mayInterruptIfRunning || (!preJob!!.isActive && !bgJob!!.isActive)) { isCancelled = true status = Status.FINISHED if (bgJob!!.isCompleted) { GlobalScope.launch(Dispatchers.Main) { onCancelled(bgJob!!.await()) } } preJob?.cancel(CancellationException("PreExecute: Coroutine Task cancelled")) bgJob?.cancel(CancellationException("doInBackground: Coroutine Task cancelled"))

        if (bgJob!!.isCancelled) {
            printLog("Bg JOB has been cancelled.")
        }
        printLog("$taskName has been cancelled.")
    }
}

JkMulti avatar Mar 01 '21 11:03 JkMulti

Please provide the code?

prajwalgambhir avatar Apr 03 '21 12:04 prajwalgambhir

Any solution for the mentioned doubt?

dineshrajamanikam avatar Aug 23 '23 19:08 dineshrajamanikam

Nope, sorry don't have any

On Thu, Aug 24, 2023, 12:16 AM dineshrajamanikam @.***> wrote:

Any solution for this above-mentioned doubt?

— Reply to this email directly, view it on GitHub https://github.com/ladrahul25/CoroutineAsyncTask/issues/2#issuecomment-1690507445, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQXA2K4OYTXGR6MNYFJVFKTXWZJJBANCNFSM4YMLSJEQ . You are receiving this because you authored the thread.Message ID: @.***>

JkMulti avatar Sep 01 '23 11:09 JkMulti