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


Namespace

OpenFGA\Network


Source

View source code


Methods

executeParallel

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.

View source


Parameters

Name Type Description
$tasks array&lt;int, callable(): T&gt;
$maxConcurrent int Maximum number of concurrent executions
$stopOnFirstError bool Stop all tasks when first error is encountered

Returns

array&lt;int, T | Throwable&gt; — Array of results or exceptions in the same order as tasks


getMaxRecommendedConcurrency

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.

View source


Returns

int — Maximum recommended concurrent tasks


supportsConcurrency

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.

View source


Returns

bool — True if concurrent execution is supported

⚠️ **GitHub.com Fallback** ⚠️