Skip to content

Files

Latest commit

 

History

History
95 lines (73 loc) · 2.28 KB

README.md

File metadata and controls

95 lines (73 loc) · 2.28 KB

PD\Async

PD\Async is a PHP library using ReactPHP to perform asynchronous tasks, supporting task dependency handling and topological sorting.

tag size
version download

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 PHP
  • react/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