diff --git a/src/Broker/TopicManager.php b/src/Broker/TopicManager.php index 2d4e41f..88b2cfd 100644 --- a/src/Broker/TopicManager.php +++ b/src/Broker/TopicManager.php @@ -33,14 +33,15 @@ class TopicManager public function subscribe(SubscriberInterface $subscriber, array $topics): void { + $this->subscribers->attach($subscriber); foreach ($topics as $topic) { $this->getTopic($topic)->addSubscriber($subscriber); } - $this->subscribers->attach($subscriber); } public function unsubscribe(SubscriberInterface $subscriber, ?array $topics=null): void { + $this->subscribers->detach($subscriber); if (!$topics) { foreach ($this->topics as $topic) { $topic->removeSubscriber($subscriber); @@ -50,7 +51,6 @@ class TopicManager foreach ($topics as $topic) { $this->getTopic($topic)->removeSubscriber($subscriber); } - $this->subscribers->detach($subscriber); } public function getTopicCount(): int