diff --git a/src/Queue.php b/src/Queue.php index 84364f32..b9bc5d48 100644 --- a/src/Queue.php +++ b/src/Queue.php @@ -10,7 +10,6 @@ use Yiisoft\Queue\Cli\LoopInterface; use Yiisoft\Queue\Message\MessageInterface; use Yiisoft\Queue\Middleware\Push\AdapterPushHandler; -use Yiisoft\Queue\Middleware\Push\PushHandlerInterface; use Yiisoft\Queue\Middleware\Push\PushMiddlewareConfig; use Yiisoft\Queue\Middleware\Push\PushMiddlewareDispatcher; use Yiisoft\Queue\Middleware\Push\SynchronousPushHandler; @@ -48,16 +47,13 @@ public function __construct( mixed ...$middlewareDefinitions, ) { $this->name = StringNormalizer::normalize($name); - $this->dispatcher = (new PushMiddlewareDispatcher( - $middlewareConfig->middlewareFactory, - $middlewareConfig->commonMiddlewareDefinitions, - $this->createFinalPushHandler(), - ))->withMiddlewaresAdded($middlewareDefinitions); - } - - public function __clone() - { - $this->dispatcher = $this->dispatcher->withFinishHandler($this->createFinalPushHandler()); + $this->dispatcher = new PushMiddlewareDispatcher( + middlewareFactory: $middlewareConfig->middlewareFactory, + middlewareDefinitions: [...$middlewareConfig->commonMiddlewareDefinitions, ...$middlewareDefinitions], + finishHandler: $this->isSynchronous() + ? new SynchronousPushHandler($this->worker, $this) + : new AdapterPushHandler($this->adapter), + ); } public function getName(): string @@ -157,13 +153,6 @@ private function handle(MessageInterface $message): bool return $this->loop->canContinue(); } - private function createFinalPushHandler(): PushHandlerInterface - { - return $this->isSynchronous() - ? new SynchronousPushHandler($this->worker, $this) - : new AdapterPushHandler($this->adapter); - } - /** * @psalm-assert-if-false !null $this->adapter */