Added sail-safe

pull/212/head
M66B 3 years ago
parent 8a166a5000
commit c2c4683d12

@ -359,11 +359,16 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
} }
void cancel(Context context) { void cancel(Context context) {
try {
ExecutorService executor = getExecutor(context); ExecutorService executor = getExecutor(context);
if (executor instanceof ThreadPoolExecutor && future instanceof Runnable) { if (executor instanceof ThreadPoolExecutor && future instanceof Runnable) {
boolean removed = ((ThreadPoolExecutor) executor).remove((Runnable) future); boolean removed = ((ThreadPoolExecutor) executor).remove((Runnable) future);
Log.i("Remove task=" + name + " removed=" + removed); Log.i("Remove task=" + name + " removed=" + removed);
} }
} catch (Throwable ex) {
Log.e(ex);
}
if (future != null && future.cancel(false)) { if (future != null && future.cancel(false)) {
Log.i("Cancelled task=" + name); Log.i("Cancelled task=" + name);
cleanup(context); cleanup(context);

Loading…
Cancel
Save