You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.")
}
}
The text was updated successfully, but these errors were encountered:
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"))
The text was updated successfully, but these errors were encountered: