correction of various problems

This commit is contained in:
ShockedPlot7560 2023-10-27 21:45:22 +02:00
parent 7e87fbbb7a
commit 5beaa3ce4e
No known key found for this signature in database
GPG Key ID: D7539B420F1FA86E
4 changed files with 4 additions and 9 deletions

View File

@ -106,7 +106,7 @@ final class AsyncEventDelegate{
$nonConcurrentHandlers = []; $nonConcurrentHandlers = [];
foreach($handlers as $registration){ foreach($handlers as $registration){
if($registration instanceof RegisteredAsyncListener){ if($registration instanceof RegisteredAsyncListener){
if($registration->canBeCallConcurrently()){ if($registration->canBeCalledConcurrently()){
$this->promises->add($registration->callAsync($this->event)); $this->promises->add($registration->callAsync($this->event));
}else{ }else{
$nonConcurrentHandlers[] = $registration; $nonConcurrentHandlers[] = $registration;

View File

@ -26,8 +26,6 @@ namespace pocketmine\event;
use pocketmine\promise\Promise; use pocketmine\promise\Promise;
trait AsyncEventTrait { trait AsyncEventTrait {
private AsyncEventDelegate $delegate;
/** /**
* @phpstan-return Promise<null> * @phpstan-return Promise<null>
*/ */

View File

@ -142,11 +142,8 @@ class HandlerList{
} }
foreach($asyncListenersByPriority as $priority => $asyncListeners){ foreach($asyncListenersByPriority as $priority => $asyncListeners){
usort($asyncListeners, static function(RegisteredAsyncListener $a, RegisteredAsyncListener $b) : int{ usort($asyncListeners, static function(RegisteredAsyncListener $a, RegisteredAsyncListener $b) : int{
if($a->canBeCallConcurrently()){ // concurrent listeners are sorted to the end of the list
return $b->canBeCallConcurrently() ? 0 : -1; return $b->canBeCalledConcurrently() <=> $a->canBeCalledConcurrently();
}else{
return $b->canBeCallConcurrently() ? -1 : 0;
}
}); });
$listenersByPriority[$priority] = array_merge($listenersByPriority[$priority] ?? [], $asyncListeners); $listenersByPriority[$priority] = array_merge($listenersByPriority[$priority] ?? [], $asyncListeners);
} }

View File

@ -51,7 +51,7 @@ class RegisteredAsyncListener extends RegisteredListener{
parent::__construct($handler, $priority, $plugin, $handleCancelled, $timings); parent::__construct($handler, $priority, $plugin, $handleCancelled, $timings);
} }
public function canBeCallConcurrently() : bool{ public function canBeCalledConcurrently() : bool{
return !$this->noConcurrentCall; return !$this->noConcurrentCall;
} }