PDPHP\Async is a PHP library using ReactPHP to perform asynchronous tasks, supporting task dependency handling and topological sorting.
- Asynchronous Task Execution
- Handling of Task Dependencies
- Ensuring correct execution order via Topological Sorting
This source code project is licensed under the GPL-3.0 license.
- PHP version 7.4 or later
- Download
Async.php
and place it in the directorysrc/PDPHP
- Add dependencies in
composer.json
{ "require": { "react/promise": "^2.8 || ^3.0", "react/event-loop": "^1.1 || ^2.0" }, "autoload": { "psr-4": { "PD\\": "src/PDPHP/" } } }
- Install dependencies
composer install
- Example
<?php require 'vendor/autoload.php'; use PDPHP\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(); });
All translations powered by ChatGPT
©️ 2024 邱敬幃 Pardn Chiu