mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-03 08:35:20 +00:00
AsyncTask: strip out task cancellation functionality
closes #5854
Cancelling task runs doesn't make any sense.
- It breaks sequential task execution - later tasks might depend on state from earlier tasks
- It doesn't actually cancel the task - at best, it prevents it from running, but cannot interrupt it (though interrupting a task does not make sense either)
We don't use this "feature" in the core anymore since 22b5e5db5e
, as this was causing unexpected behaviour for plugins anyway, along with the occasional shutdown crash due to inconsistent worker states.
This commit is contained in:
@ -259,7 +259,7 @@ class AsyncPool{
|
||||
if($task->isTerminated()){
|
||||
$this->checkCrashedWorker($worker, $task);
|
||||
throw new AssumptionFailedError("checkCrashedWorker() should have thrown an exception, making this unreachable");
|
||||
}elseif(!$task->hasCancelledRun()){
|
||||
}else{
|
||||
/*
|
||||
* It's possible for a task to submit a progress update and then finish before the progress
|
||||
* update is detected by the parent thread, so here we consume any missed updates.
|
||||
|
@ -72,17 +72,14 @@ abstract class AsyncTask extends Runnable{
|
||||
private ?ThreadSafeArray $progressUpdates = null;
|
||||
|
||||
private ThreadSafe|string|int|bool|null|float $result = null;
|
||||
private bool $cancelRun = false;
|
||||
private bool $submitted = false;
|
||||
|
||||
private bool $submitted = false;
|
||||
private bool $finished = false;
|
||||
|
||||
public function run() : void{
|
||||
$this->result = null;
|
||||
|
||||
if(!$this->cancelRun){
|
||||
$this->onRun();
|
||||
}
|
||||
$this->onRun();
|
||||
|
||||
$this->finished = true;
|
||||
$worker = NativeThread::getCurrentThread();
|
||||
@ -123,12 +120,18 @@ abstract class AsyncTask extends Runnable{
|
||||
$this->result = is_scalar($result) || is_null($result) || $result instanceof ThreadSafe ? $result : new NonThreadSafeValue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
public function cancelRun() : void{
|
||||
$this->cancelRun = true;
|
||||
//NOOP
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
public function hasCancelledRun() : bool{
|
||||
return $this->cancelRun;
|
||||
return false;
|
||||
}
|
||||
|
||||
public function setSubmitted() : void{
|
||||
|
Reference in New Issue
Block a user