Skip to content

Commit

Permalink
fix race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
joedixon committed May 8, 2024
1 parent 9ac51d3 commit 0612fad
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/Servers/Reverb/Publishing/RedisPubSubProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ public function subscribe(): void
{
$this->ensureConnected();

$this->subscribingClient->subscribe($this->channel);

$this->subscribingClient->on('message', function (string $channel, string $payload) {
$this->messageHandler->handle($payload);
});
$this->subscribingClient->subscribe($this->channel)
->then(function () {
$this->subscribingClient->on('message', function (string $channel, string $payload) {
$this->messageHandler->handle($payload);
});
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,13 @@
});

it('can gather data for a single channel', function () {
$start = microtime(true);
$this->usingRedis();

subscribe('test-channel-one');
subscribe('test-channel-one');

$response = await($this->signedRequest('channels/test-channel-one?info=user_count,subscription_count,cache'));

dump("Time: %f\n", microtime(true) - $start);
expect($response->getStatusCode())->toBe(200);
expect($response->getBody()->getContents())->toBe('{"occupied":true,"subscription_count":2}');
});
Expand Down

0 comments on commit 0612fad

Please sign in to comment.