All Projects → alash3al → axync

alash3al / axync

Licence: MIT license
a smart cooperative multitasking kernel for php7

Programming Languages

PHP
23972 projects - #3 most used programming language

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 .
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].