pardnchiu / async
PD\Async is a PHP library using ReactPHP to perform asynchronous tasks, supporting task dependency handling and topological sorting.
1.0.0
2025-02-02 19:53 UTC
Requires
- php: >=7.4
- react/event-loop: ^1.1 || ^2.0
- react/promise: ^2.8 || ^3.0
README
PD\Async is a PHP library using ReactPHP to perform asynchronous tasks, supporting task dependency handling and topological sorting.
Features
- Asynchronous Task Execution
- Handling of Task Dependencies
- Ensuring correct execution order via Topological Sorting
Key Capabilities
- Non-blocking Task Processing
- Task Dependency Management
- Smart Execution Ordering
- Promise Error Handling
- Flexible Task Configuration
Dependencies
react/promise
- Promise/A+ for PHPreact/event-loop
- Event Loop Library for PHP
How to Use
Install
composer require pardnchiu/async
<?php use PD\Async; $tasks = [ 'task1' => [ 'method' => function () { return 'result1'; }, 'tasks' => [], ], 'task2' => [ 'method' => function () { return 'result2'; }, 'tasks' => ['task1'], // Run after task1 ], 'task3' => [ 'method' => function () { return 'result3'; }, 'tasks' => ['task1'], // Run after task1 ], 'task4' => [ 'method' => function () { return 'result3'; }, 'tasks' => ['task2'], // Run after task2 ], ]; Async::run($tasks) ->then(function ($results) { print_r($results); }) ->catch(function ($error) { echo 'Error: ' . $error->getMessage(); });
License
This source code project is licensed under the MIT license.
Creator
邱敬幃 Pardn Chiu
©️ 2024 邱敬幃 Pardn Chiu