Skip to content

Commit

Permalink
Simplify handler sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
dktapps authored Nov 14, 2024
1 parent 117026c commit d2d663b
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/event/AsyncHandlerListManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,9 @@ protected function getBaseEventClass() : string{
*/
private static function sortSamePriorityHandlers(array $listeners) : array{
uasort($listeners, function(AsyncRegisteredListener $left, AsyncRegisteredListener $right) : int{
//While the system can handle these in any order, it's better for latency if concurrent handlers
//are processed together. It doesn't matter whether they are processed before or after exclusive handlers.
if($right->canBeCalledConcurrently()){
return $left->canBeCalledConcurrently() ? 0 : 1;
}
return -1;
//Promise::all() can be used more efficiently if concurrent handlers are grouped together.
//It's not important whether they are grouped before or after exclusive handlers.
return $left->canBeCalledConcurrently() <=> $right->canBeCalledConcurrently();
});
return $listeners;
}
Expand Down

0 comments on commit d2d663b

Please sign in to comment.