From a88ba722c1cabb3c581a0944791cadd449d9812d Mon Sep 17 00:00:00 2001 From: chaz6chez Date: Sun, 19 Nov 2023 17:56:12 +0800 Subject: [PATCH] fixed #18 --- src/Connection.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Connection.php b/src/Connection.php index 7424eb1..4a331cc 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -191,22 +191,24 @@ public function syncPublish(BuilderConfig $config, bool $close = false): bool $config->getQueue(), $config->getExchange(), $config->getRoutingKey(), $config->isNowait(), $config->getArguments() ); - }catch (Throwable $throwable){ + } catch (Throwable $throwable){ if($this->getErrorCallback()){\call_user_func($this->getErrorCallback(), $throwable, $this);} $this->close($this->getSyncClient(), $throwable); return false; } } - - return $channel->publish( - $config->getBody(), $config->getHeaders(), $config->getExchange(), $config->getRoutingKey(), - $config->isMandatory(), $config->isImmediate() - )->then(function () use ($close) { - if($close) {$this->close($this->getAsyncClient());} - }, function (Throwable $throwable) { + try { + $res = (bool)$channel->publish( + $config->getBody(), $config->getHeaders(), $config->getExchange(), $config->getRoutingKey(), + $config->isMandatory(), $config->isImmediate() + ); + if($close) {$this->close($this->getSyncClient());} + return $res; + } catch (Throwable $throwable){ if($this->getErrorCallback()){\call_user_func($this->getErrorCallback(), $throwable, $this);} $this->close($this->getSyncClient(), $throwable); - })->done(); + return false; + } } /**