PHP Classes

Axync: Run several tasks using cooperative multitasking

Recommend this page to a friend!
  Info   View files Documentation   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 69%Total: 407 All time: 6,497 This week: 190Up
Version License PHP version Categories
axync 1.0MIT/X Consortium ...7.0Language, PHP 7
Description 

Author

This class can run several tasks using cooperative multitasking.

It can takes one or more callback functions that will do the work of different tasks.

The class will execute the registered functions in a loop until all functions are finished.

The functions should use the PHP yield command after they do their work, so they allow the next function to do its part of the work.

The class can also return a generator that can be used by another object of the class to iterate over a list of callable functions or generators, thus implemented nested cooperative multitasking.

Innovation Award
PHP Programming Innovation award nominee
March 2016
Number 2
Cooperative multitasking is a way to execute multiple tasks concurrently. Only one task runs at each moment but it gives the turn to the next task in the list of concurrent tasks.

This class implements a manager for cooperative multitasking in pure PHP that relies on generators to let one task decide when it can give the control to the next task.

Manuel Lemos
Picture of Mohammed Al Ashaal
  Performance   Level  
Name: Mohammed Al Ashaal <contact>
Classes: 8 packages by
Country: Egypt Egypt
Age: 30
All time rank: 128111 in Egypt Egypt
Week rank: 312 Up3 in Egypt Egypt Up
Innovation award
Innovation award
Nominee: 2x

Winner: 1x

Documentation

axync

a smart cooperative multitasking kernel for php7 (only) .

show me the code !

Example 1 (simple)

  require "axync.php";

  // our workers builder
	$build = function($seq){
	  // this will be the generated coroutine
	  // yes, it MUST yield !
		return (function() use($seq) {
			for ( $i = 0; $i < 10; $i ++ ) {
				printf("Worker (%d): i'm in the step no. %d \n", $seq, $i);
				yield;
			}
		});
	};  
  
  // create new manager
  (new Axync(
    $build(1),
    $build(2),
    $build(3)
  ))->exec();

  // save your file as ~/tst1.php
  // open your terminal and `php ~/tst1.php` and see the result .

Example 2 (advanced)

  require "axync.php";

  // our workers builder
	$build = function($seq){
	  // this will be the generated coroutine
	  // yes, it MUST yield !
		return (function() use($seq) {
			for ( $i = 0; $i < 10; $i ++ ) {
				printf("Worker (%d): i'm in the step no. %d \n", $seq, $i);
				yield;
			}
		});
	};  
  
  // create new manager
  // and convert to to a new Generator !!
 $manager1 = (new Axync(
    $build(1),
    $build(2),
    $build(3)
  ))->toGenerator();

  // create a new manager that handles new generators
  (new Axync(
    $build(10),
    $build(20),
    $build(30),
    $manager1 // yes, axync support nested axync of axync too ;)
  ))->exec();

  // save your file as ~/tst2.php
  // open your terminal and `php ~/tst2.php` and see the result .

  Files folder image Files  
File Role Description
Plain text file axync.php Class Class source
Accessible without login Plain text file LICENSE Lic. License
Accessible without login Plain text file README.md Doc. Documentation

 Version Control Unique User Downloads Download Rankings  
 100%
Total:407
This week:0
All time:6,497
This week:190Up
 User Ratings  
 
 All time
Utility:100%StarStarStarStarStarStar
Consistency:100%StarStarStarStarStarStar
Documentation:90%StarStarStarStarStar
Examples:-
Tests:-
Videos:-
Overall:69%StarStarStarStar
Rank:364