API Network ConcurrentExecutorInterface - evansims/openfga-php GitHub Wiki
Interface for concurrent task execution. This interface defines the contract for executing multiple tasks concurrently, providing improved performance for batch operations. Implementations can use different concurrency strategies such as Fibers, threads, or process pools.
Table of Contents
OpenFGA\Network
public function executeParallel(
array<int, callable(): T> $tasks,
int $maxConcurrent = 10,
bool $stopOnFirstError = false,
): array<int, T|Throwable>
Execute multiple tasks in parallel. Executes the provided tasks concurrently up to the specified concurrency limit. Tasks are executed as they become available and results are collected in the same order as the input tasks.
Name | Type | Description |
---|---|---|
$tasks |
array< int, callable(): T>
|
|
$maxConcurrent |
int |
Maximum number of concurrent executions |
$stopOnFirstError |
bool |
Stop all tasks when first error is encountered |
array<int, T
| Throwable>
— Array of results or exceptions in the same order as tasks
public function getMaxRecommendedConcurrency(): int
Get the maximum recommended concurrency for the current environment. This provides a hint about the optimal concurrency level based on system resources and implementation constraints.
int
— Maximum recommended concurrent tasks
public function supportsConcurrency(): bool
Check if the executor supports concurrent execution. Some environments may not support true concurrency (for example missing Fiber support in PHP < 8.1). This method allows checking if the executor can actually run tasks concurrently or will fall back to sequential execution.
bool
— True if concurrent execution is supported