Skip to content

Commit 8291754

Browse files
committed
allow to specify the retry periods
1 parent 3c1dea6 commit 8291754

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [Unreleased]
4+
5+
### Added
6+
7+
- `Innmind\HttpTransport\Transport::exponentialBackoff()` now accepts a third parameter to specify the retry periods
8+
39
## 9.0.0 - 2026-02-01
410

511
### Added

src/ExponentialBackoff.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,19 @@ public function __invoke(Request $request): Either
4242

4343
/**
4444
* @psalm-pure
45+
*
46+
* @param ?Sequence<Period> $retries
4547
*/
46-
public static function of(Implementation $fulfill, Halt $halt): self
47-
{
48+
public static function of(
49+
Implementation $fulfill,
50+
Halt $halt,
51+
?Sequence $retries = null,
52+
): self {
4853
/** @psalm-suppress ArgumentTypeCoercion Periods are necessarily positive */
4954
return new self(
5055
$fulfill,
5156
$halt,
52-
Sequence::of(
57+
$retries ?? Sequence::of(
5358
Period::millisecond((int) (\exp(0) * 100.0)),
5459
Period::millisecond((int) (\exp(1) * 100.0)),
5560
Period::millisecond((int) (\exp(2) * 100.0)),

src/Transport.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
Period,
1111
Halt,
1212
};
13-
use Innmind\Immutable\Either;
13+
use Innmind\Immutable\{
14+
Either,
15+
Sequence,
16+
};
1417
use Psr\Log\LoggerInterface;
1518

1619
/**
@@ -51,13 +54,18 @@ public static function circuitBreaker(
5154
));
5255
}
5356

57+
/**
58+
* @param ?Sequence<Period> $retries
59+
*/
5460
public static function exponentialBackoff(
5561
self $transport,
5662
Halt $halt,
63+
?Sequence $retries = null,
5764
): self {
5865
return new self(ExponentialBackoff::of(
5966
$transport->implementation,
6067
$halt,
68+
$retries,
6169
));
6270
}
6371

0 commit comments

Comments
 (0)