Releases: ElementaryFramework/Async
Releases · ElementaryFramework/Async
v1.0.0
Added
Core Features
- Promise/A+ Implementation - Full compliance with the Promise/A+ specification for JavaScript-like promise handling in PHP
- Fiber-Based Execution - Leverages PHP 8.1+ Fibers for true asynchronous, non-blocking operations
- Event Loop - Built-in event loop for managing async operations, timers, and deferred tasks
- Type-Safe Generics - Full PHP generics support with proper type annotations for better IDE support and type safety
Promise API
Promiseclass withthen(),catch(), andfinally()methodsDeferredclass for manual promise resolution/rejection controlPromiseInterfacefor consistent promise behavior across the libraryPromiseStateenum (PENDING, FULFILLED, REJECTED) for state management
Static Factory Methods
Async::resolve()- Create immediately resolved promisesAsync::reject()- Create immediately rejected promisesAsync::run()- Execute functions asynchronously
Promise Combinators
Async::all()- Wait for all promises to complete successfullyAsync::race()- Return the first settled promise resultAsync::any()- Return the first successful promise, ignore failuresAsync::allSettled()- Wait for all promises to settle, regardless of outcome
Timing and Control
Async::delay()- Create promises that resolve after a specified delayAsync::timeout()- Wrap operations with timeout constraintsAsync::setTimeout()- Schedule callbacks for future executionAsync::setInterval()- Schedule recurring callbacksAsync::clearTimer()- Cancel timeouts and recurring intervals
Cancellation Support
CancellationTokenandCancellationTokenInterfacefor cancellation propagationCancellationTokenSourcefor creating and managing cancellation tokensCombinedCancellationTokenfor linking multiple cancellation sourcesAsync::createCancellationTokenSource()- Factory for cancellation token sourcesAsync::createTimeoutTokenSource()- Auto-cancelling token source with timeoutAsync::combineCancellationTokens()- Combine multiple cancellation tokens- Signal-based cancellation support via PCNTL extension (optional)
Concurrency Control
Async::pool()- Execute tasks with configurable concurrency limitsAsync::retry()- Retry failed operations with exponential backoffAsync::debounce()- Debounce function calls to prevent excessive executionAsync::throttle()- Throttle function calls to limit execution frequency
Utility Functions
Async::yield()- Yield control to the event loop for cooperative multitaskingAsync::await()- Wait for all pending async operations to completeAsync::startEventLoop()- Initialize and start the event loopAsync::stopEventLoop()- Gracefully stop the event loopAsync::supportsPCNTL()- Check for PCNTL extension availability
Exception Handling
CancellationException- Thrown when operations are cancelledAggregateException- Container for multiple exceptions from parallel operations- Proper exception propagation through promise chains
Global Functions
async()- Alias forAsync::run()await()- Alias forAsync::await()delay()- Alias forAsync::delay()all()- Alias forAsync::all()race()- Alias forAsync::race()any()- Alias forAsync::any()allSettled()- Alias forAsync::allSettled()
Developer Experience
- Comprehensive PHPDoc annotations for IDE support
- Full test coverage with Pest PHP testing framework
- Static analysis support with PHPStan