Skip to content
/ dag Public

Directed acyclic graph of tasks implementation based on Amphp promises

License

Notifications You must be signed in to change notification settings

dbalabka/dag

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This experimental library helps to organize tasks and its dependencies. Amphp framework support provide ability to execute tasks asynchronously.

Following example show basic usage:

$taskDag = (new TaskGraph())
    
    // root task in graph (there might be multiple root tasks)
    ->addTask(new ClosureTask('1', function () {
        echo $this->name;
    }))
    
    // these two tasks were be executed only after task with name '1'
    // the order of execution is not guaranteed
    ->addTask(new ClosureTask('2', function () {
        echo 2;
    }, ['1'])) 
    ->addTask(new ClosureTask('3', function () {
        echo 3;
    }, ['1']))

    // this is the last task in graph (there might be multiple leaf tasks)
    ->addTask(new ClosureTask('4', function () {
        echo 4;
    }, ['3', '2']));

Amp\Loop::run($taskDag); // will output "1234"

The visualization of the execution graph will be following:

     +------+
   +-+Task 1+-+
   | +------+ |
   |          |
+--v---+  +---v--+
|Task 2|  |Task 3|
+--+---+  +---+--+
   |          |
   | +------+ |
   +->Task 4<-+
     +------+

About

Directed acyclic graph of tasks implementation based on Amphp promises

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages