Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 8 additions & 3 deletions src/ExponentialBackoff.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,19 @@ public function __invoke(Request $request): Either

/**
* @psalm-pure
*
* @param ?Sequence<Period> $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)),
Expand Down
10 changes: 9 additions & 1 deletion src/Transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
Period,
Halt,
};
use Innmind\Immutable\Either;
use Innmind\Immutable\{
Either,
Sequence,
};
use Psr\Log\LoggerInterface;

/**
Expand Down Expand Up @@ -51,13 +54,18 @@ public static function circuitBreaker(
));
}

/**
* @param ?Sequence<Period> $retries
*/
public static function exponentialBackoff(
self $transport,
Halt $halt,
?Sequence $retries = null,
): self {
return new self(ExponentialBackoff::of(
$transport->implementation,
$halt,
$retries,
));
}

Expand Down
Loading