Skip to content

(integration) An asynchronous task library built on ReactPHP, enabling dependency-based sorting with topological ordering for precise and efficient workflow management.

License

Notifications You must be signed in to change notification settings

pardnchiu/PDPHP-Async

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

PDPHP\Async (PHP Library)

PDPHP\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

創建者 / Creator

邱敬幃 Pardn Chiu

License

This source code project is licensed under the GPL-3.0 license.

How to Use

  • PHP version 7.4 or later
  • Download Async.php and place it in the directory src/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

About

(integration) An asynchronous task library built on ReactPHP, enabling dependency-based sorting with topological ordering for precise and efficient workflow management.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages