class Parallel

Properties

protected array<array-key, callable> $callbacks
protected Channel|null $concurrentChannel
protected array<array-key, mixed> $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 48
__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. Objects stored directly in context are shared by reference by default. Values implementing Hypervel\Context\ReplicableContext are copied via replicate(), while values implementing Hypervel\Context\NonCopyableContext are omitted.

at line 60
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 77
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
RunningInNonCoroutineException

at line 212
int count()

Get the number of registered callbacks.

Return Value

int

at line 222
array getThrowables()

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

Return Value

array

at line 230
bool hasFailures()

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

Return Value

bool

at line 238
int failedCount()

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

Return Value

int

at line 246
void clear()

Clear all callbacks, results, and throwables.

Return Value

void