API Network SimpleConcurrentExecutor - evansims/openfga-php GitHub Wiki

Simple concurrent executor implementation. This implementation provides a fallback for environments without Fiber support. It executes tasks sequentially while maintaining the same interface as the fiber-based implementation.

Table of Contents


Namespace

OpenFGA\Network


Source

View source code


Implements


Methods

executeParallel

public function executeParallel(array $tasks, int $maxConcurrent = 10, bool $stopOnFirstError = false): array

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
$maxConcurrent int Maximum number of concurrent executions
$stopOnFirstError bool Stop all tasks when first error is encountered

Returns

array — 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** ⚠️