Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  specify next release
  add Config::withHttpHeartbeat()
  • Loading branch information
Baptouuuu committed Nov 5, 2023
2 parents 5d896d7 + b7de5ab commit 677d0a0
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 4.1.0 - 2023-11-05

### Added

- `Innmind\OperatingSystem\Config::withHttpHeartbeat()`

## 4.0.0 - 2023-10-22

### Added
Expand Down
43 changes: 43 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ final class Config
private EnvironmentPath $path;
/** @var Maybe<positive-int> */
private Maybe $maxHttpConcurrency;
/** @var Maybe<array{ElapsedPeriod, callable(): void}> */
private Maybe $httpHeartbeat;

/**
* @param Maybe<positive-int> $maxHttpConcurrency
* @param Maybe<array{ElapsedPeriod, callable(): void}> $httpHeartbeat
*/
private function __construct(
Clock $clock,
Expand All @@ -40,6 +43,7 @@ private function __construct(
Halt $halt,
EnvironmentPath $path,
Maybe $maxHttpConcurrency,
Maybe $httpHeartbeat,
) {
$this->clock = $clock;
$this->caseSensitivity = $caseSensitivity;
Expand All @@ -48,12 +52,15 @@ private function __construct(
$this->halt = $halt;
$this->path = $path;
$this->maxHttpConcurrency = $maxHttpConcurrency;
$this->httpHeartbeat = $httpHeartbeat;
}

public static function of(): self
{
/** @var Maybe<positive-int> */
$maxHttpConcurrency = Maybe::nothing();
/** @var Maybe<array{ElapsedPeriod, callable(): void}> */
$httpHeartbeat = Maybe::nothing();

return new self(
new Earth\Clock,
Expand All @@ -66,6 +73,7 @@ public static function of(): self
new Halt\Usleep,
EnvironmentPath::of(\getenv('PATH') ?: ''),
$maxHttpConcurrency,
$httpHeartbeat,
);
}

Expand All @@ -82,6 +90,7 @@ public function withClock(Clock $clock): self
$this->halt,
$this->path,
$this->maxHttpConcurrency,
$this->httpHeartbeat,
);
}

Expand All @@ -98,6 +107,7 @@ public function caseInsensitiveFilesystem(): self
$this->halt,
$this->path,
$this->maxHttpConcurrency,
$this->httpHeartbeat,
);
}

Expand All @@ -118,6 +128,7 @@ public function useStreamCapabilities(Capabilities $capabilities): self
$this->halt,
$this->path,
$this->maxHttpConcurrency,
$this->httpHeartbeat,
);
}

Expand All @@ -134,6 +145,7 @@ public function haltProcessVia(Halt $halt): self
$halt,
$this->path,
$this->maxHttpConcurrency,
$this->httpHeartbeat,
);
}

Expand All @@ -150,6 +162,7 @@ public function withEnvironmentPath(EnvironmentPath $path): self
$this->halt,
$path,
$this->maxHttpConcurrency,
$this->httpHeartbeat,
);
}

Expand All @@ -168,6 +181,26 @@ public function limitHttpConcurrencyTo(int $max): self
$this->halt,
$this->path,
Maybe::just($max),
$this->httpHeartbeat,
);
}

/**
* @psalm-mutation-free
*
* @param callable(): void $heartbeat
*/
public function withHttpHeartbeat(ElapsedPeriod $timeout, callable $heartbeat): self
{
return new self(
$this->clock,
$this->caseSensitivity,
$this->streamCapabilities,
$this->io,
$this->halt,
$this->path,
$this->maxHttpConcurrency,
Maybe::just([$timeout, $heartbeat]),
);
}

Expand Down Expand Up @@ -228,4 +261,14 @@ public function maxHttpConcurrency(): Maybe
{
return $this->maxHttpConcurrency;
}

/**
* @internal
*
* @return Maybe<array{ElapsedPeriod, callable(): void}>
*/
public function httpHeartbeat(): Maybe
{
return $this->httpHeartbeat;
}
}
9 changes: 7 additions & 2 deletions src/Remote/Generic.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,16 @@ public function http(): HttpTransport
$this->config->streamCapabilities(),
$this->config->io(),
);

return $this->http = $this->config->maxHttpConcurrency()->match(
$http = $this->config->maxHttpConcurrency()->match(
static fn($max) => $http->maxConcurrency($max),
static fn() => $http,
);
$http = $this->config->httpHeartbeat()->match(
static fn($config) => $http->heartbeat($config[0], $config[1]),
static fn() => $http,
);

return $this->http = $http;
}

public function sql(Url $server): Connection
Expand Down

0 comments on commit 677d0a0

Please sign in to comment.