Prevent multiple watchers for one topic
This commit is contained in:
@@ -28,6 +28,8 @@ final class Lookup
|
|||||||
|
|
||||||
private array $running = [];
|
private array $running = [];
|
||||||
|
|
||||||
|
private array $topicWatchers = [];
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private array $addresses,
|
private array $addresses,
|
||||||
private LookupConfig $config,
|
private LookupConfig $config,
|
||||||
@@ -183,8 +185,16 @@ final class Lookup
|
|||||||
|
|
||||||
private function watch(string $topic): void
|
private function watch(string $topic): void
|
||||||
{
|
{
|
||||||
|
if (\array_key_exists($topic, $this->topicWatchers)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->topicWatchers[$topic] = true;
|
||||||
|
|
||||||
asyncCall(function () use ($topic) {
|
asyncCall(function () use ($topic) {
|
||||||
$requestHandler = function (string $uri) use ($topic): \Generator {
|
$requestHandler = function (string $uri) use ($topic): \Generator {
|
||||||
|
$this->logger->debug('Lookup', compact('topic'));
|
||||||
|
|
||||||
/** @var Response $response */
|
/** @var Response $response */
|
||||||
$response = yield $this->httpClient->request(new Request($uri.'/lookup?topic='.$topic));
|
$response = yield $this->httpClient->request(new Request($uri.'/lookup?topic='.$topic));
|
||||||
|
|
||||||
@@ -221,6 +231,8 @@ final class Lookup
|
|||||||
|
|
||||||
yield delay($this->config->pollingInterval);
|
yield delay($this->config->pollingInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unset($this->topicWatchers[$topic]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user