From 82917541cc4a3c260ea705932ed3807b737c00a1 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Thu, 9 Apr 2026 10:34:49 +0200 Subject: [PATCH] allow to specify the retry periods --- CHANGELOG.md | 6 ++++++ src/ExponentialBackoff.php | 11 ++++++++--- src/Transport.php | 10 +++++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae0cd94..0d02b2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [Unreleased] + +### Added + +- `Innmind\HttpTransport\Transport::exponentialBackoff()` now accepts a third parameter to specify the retry periods + ## 9.0.0 - 2026-02-01 ### Added diff --git a/src/ExponentialBackoff.php b/src/ExponentialBackoff.php index 304b46a..f34f309 100644 --- a/src/ExponentialBackoff.php +++ b/src/ExponentialBackoff.php @@ -42,14 +42,19 @@ public function __invoke(Request $request): Either /** * @psalm-pure + * + * @param ?Sequence $retries */ - public static function of(Implementation $fulfill, Halt $halt): self - { + public static function of( + Implementation $fulfill, + Halt $halt, + ?Sequence $retries = null, + ): self { /** @psalm-suppress ArgumentTypeCoercion Periods are necessarily positive */ return new self( $fulfill, $halt, - Sequence::of( + $retries ?? Sequence::of( Period::millisecond((int) (\exp(0) * 100.0)), Period::millisecond((int) (\exp(1) * 100.0)), Period::millisecond((int) (\exp(2) * 100.0)), diff --git a/src/Transport.php b/src/Transport.php index 4ed65b0..1ba43dc 100644 --- a/src/Transport.php +++ b/src/Transport.php @@ -10,7 +10,10 @@ Period, Halt, }; -use Innmind\Immutable\Either; +use Innmind\Immutable\{ + Either, + Sequence, +}; use Psr\Log\LoggerInterface; /** @@ -51,13 +54,18 @@ public static function circuitBreaker( )); } + /** + * @param ?Sequence $retries + */ public static function exponentialBackoff( self $transport, Halt $halt, + ?Sequence $retries = null, ): self { return new self(ExponentialBackoff::of( $transport->implementation, $halt, + $retries, )); }