mirror of https://github.com/M66B/FairEmail.git
Dequeue cancelled tasks
This commit is contained in:
parent
1cf9365c76
commit
2542018ca9
|
@ -45,6 +45,8 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.RunnableFuture;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
// This simple task is simple to use, but it is also simple to cause bugs that can easily lead to crashes
|
||||
// Make sure to not access any member in any outer scope from onExecute
|
||||
|
@ -358,6 +360,11 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
|||
}
|
||||
|
||||
void cancel(Context context) {
|
||||
ExecutorService executor = getExecutor(context);
|
||||
if (executor instanceof ThreadPoolExecutor && future instanceof Runnable) {
|
||||
boolean removed = ((ThreadPoolExecutor) executor).remove((Runnable) future);
|
||||
Log.i("Remove task=" + name + " removed=" + removed);
|
||||
}
|
||||
if (future != null && future.cancel(false)) {
|
||||
Log.i("Cancelled task=" + name);
|
||||
cleanup(context);
|
||||
|
|
Loading…
Reference in New Issue