VOOZH about

URL: https://deepwiki.com/hypervel/coroutine/2.2-concurrent-execution

⇱ Concurrent Execution | hypervel/coroutine | DeepWiki


Loading...
Menu

Concurrent Execution

This document covers the Concurrent class in the Hypervel coroutine package, which provides enhanced concurrent execution capabilities with integrated exception reporting. The Concurrent class extends Hyperf's base concurrent functionality to add framework-specific exception handling mechanisms.

For basic coroutine creation and lifecycle management, see Base Coroutine Class. For global utility functions that provide convenient APIs for concurrent execution, see Parallel Execution.

Purpose and Architecture

The Concurrent class serves as an enhanced wrapper around Hyperf's BaseConcurrent implementation, adding exception reporting capabilities that integrate with Hypervel's exception handling infrastructure. It manages the execution of multiple coroutines with controlled concurrency limits while ensuring exceptions are properly captured and reported.

Class Architecture


Sources: src/Concurrent.php1-51

Core Execution Flow

The Concurrent class implements controlled concurrent execution through its create method, which wraps each callable in a coroutine with exception handling and channel-based concurrency management.

Concurrent Execution Flow


Sources: src/Concurrent.php16-29

Exception Reporting Mechanism

The reportException method implements a tiered exception handling strategy that prioritizes custom exception handlers while providing fallback mechanisms for logging.

PriorityHandler TypeInterfaceBehavior
1Custom HandlerExceptionHandlerContractCalls report() method
2Formatted LoggerStdoutLoggerInterface + FormatterInterfaceFormats and logs as error
3Silent FailureN/ANo container available

Exception Reporting Decision Tree


Sources: src/Concurrent.php31-50

Integration Patterns

The Concurrent class integrates with the broader Hypervel ecosystem through several key integration points:

Dependency Injection Integration

The class relies on ApplicationContext for service resolution, enabling flexible exception handling strategies:

  • Custom Exception Handler: Integrates with Hypervel's exception handling contracts
  • Stdout Logger: Falls back to Hyperf's standard logging infrastructure
  • Formatter Interface: Provides structured exception formatting when available

Coroutine Integration

The create method delegates coroutine creation to Hypervel\Coroutine\Coroutine, ensuring consistent coroutine lifecycle management and exception reporting across the entire package.

Component Integration Map


Sources: src/Concurrent.php7-11 src/Concurrent.php20 src/Concurrent.php33-49