class Parallel

Properties

protected array<array-key, callable> $callbacks
protected Channel|null $concurrentChannel
protected array $results
protected Throwable> $throwables

Methods

__construct(int $concurrent = 0, bool|array $copyContext = false)

Create a new parallel executor.

void
add(callable $callable, int|string|null $key = null)

Add a callback to be executed in parallel.

array
wait(bool $throw = true)

Execute all callbacks in parallel and wait for completion.

int
count()

Get the number of registered callbacks.

array
getThrowables()

Get the throwables captured from the most recent wait() call, keyed by callback key.

bool
hasFailures()

Determine if the most recent wait() call captured any throwables.

int
failedCount()

Get the number of throwables captured from the most recent wait() call.

void
clear()

Clear all callbacks, results, and throwables.

Details

at line 38
__construct(int $concurrent = 0, bool|array $copyContext = false)

Create a new parallel executor.

Parameters

int $concurrent

Maximum concurrent coroutines (0 = unlimited)

bool|array $copyContext

When set, parent coroutine context is copied to each child. false = fresh context (default), true or empty array = copy all keys, non-empty array = copy listed keys only. Object values from the parent context are shared by reference; values implementing Hypervel\Context\ReplicableContext are deep-copied via replicate().

at line 50
void add(callable $callable, int|string|null $key = null)

Add a callback to be executed in parallel.

Parameters

callable $callable
int|string|null $key

Return Value

void

at line 66
array wait(bool $throw = true)

Execute all callbacks in parallel and wait for completion.

Parameters

bool $throw

Whether to throw on errors

Return Value

array

The results keyed by callback key

Exceptions

ParallelExecutionException

at line 127
int count()

Get the number of registered callbacks.

Return Value

int

at line 137
array getThrowables()

Get the throwables captured from the most recent wait() call, keyed by callback key.

Return Value

array

at line 145
bool hasFailures()

Determine if the most recent wait() call captured any throwables.

Return Value

bool

at line 153
int failedCount()

Get the number of throwables captured from the most recent wait() call.

Return Value

int

at line 161
void clear()

Clear all callbacks, results, and throwables.

Return Value

void