From bc1eae3016a2b6f94784883903286b3406b34295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Isaert?= Date: Mon, 6 Nov 2023 15:56:56 +0100 Subject: [PATCH] fix: add `readTimeout` on factory and use it only as float --- README.md | 2 +- src/Hub/Transport/Redis/RedisTransport.php | 2 +- src/Hub/Transport/Redis/RedisTransportFactory.php | 1 + src/functions.php | 4 ++-- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ceaa7d0..249cff5 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ TRANSPORT_DSN="redis://127.0.0.1:6379" ./bin/freddie Optional parameters you can pass in the DSN's query string: - `pingInterval` - regularly ping Redis connection, which will help detect outages (default `2.0`) -- `readTimeout` - max duration in seconds of a ping or publish request (default `null`) +- `readTimeout` - max duration in seconds of a ping or publish request (default `0.0`: considered disabled) _Alternatively, you can set this variable into `.env.local`._ diff --git a/src/Hub/Transport/Redis/RedisTransport.php b/src/Hub/Transport/Redis/RedisTransport.php index 857b9c3..6d3e35d 100644 --- a/src/Hub/Transport/Redis/RedisTransport.php +++ b/src/Hub/Transport/Redis/RedisTransport.php @@ -44,7 +44,7 @@ public function __construct( 'channel' => 'mercure', 'key' => 'mercureUpdates', 'pingInterval' => 2.0, - 'readTimeout' => null, + 'readTimeout' => 0.0, ]); $this->options = $resolver->resolve($options); if ($this->options['pingInterval']) { diff --git a/src/Hub/Transport/Redis/RedisTransportFactory.php b/src/Hub/Transport/Redis/RedisTransportFactory.php index f2c1e1c..1b63362 100644 --- a/src/Hub/Transport/Redis/RedisTransportFactory.php +++ b/src/Hub/Transport/Redis/RedisTransportFactory.php @@ -39,6 +39,7 @@ public function create(string $dsn): TransportInterface 'size' => (int) max(0, $parsed->getParameter('size', 0)), 'trimInterval' => (float) max(0, $parsed->getParameter('trimInterval', 0.0)), 'pingInterval' => (float) max(0, $parsed->getParameter('pingInterval', 2.0)), + 'readTimeout' => (float) max(0, $parsed->getParameter('readTimeout', 0.0)), 'channel' => (string) $parsed->getParameter('channel', 'mercure'), 'key' => (string) $parsed->getParameter('key', 'mercureUpdates'), ], diff --git a/src/functions.php b/src/functions.php index e13be79..6502de8 100644 --- a/src/functions.php +++ b/src/functions.php @@ -61,7 +61,7 @@ function extract_last_event_id(ServerRequestInterface $request): ?string * @param PromiseInterface $promise * @return PromiseInterface */ -function maybeTimeout(PromiseInterface $promise, ?float $time = null): PromiseInterface +function maybeTimeout(PromiseInterface $promise, float $time = 0.0): PromiseInterface { - return null === $time ? $promise : timeout($promise, $time); + return 0.0 === $time ? $promise : timeout($promise, $time); }