2017 © Pedro Peláez
 

library async-generator

An async generator runtime for PHP

image

jubianchi/async-generator

An async generator runtime for PHP

  • Saturday, March 18, 2017
  • by jubianchi
  • Repository
  • 7 Watchers
  • 37 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

async-generator

This project is in early alpha and is more a like a POC than a real production-ready library., (*1)

Requirements

The async-generator library requires PHP ^7.0.3(i.e PHP >= 7.0.3 && < 8.0.0), (*2)

Install

Use Composer to install this library into your project:, (*3)

{
    "require": {
        "jubianchi/async-generator": "@stable"
    }
}

Then run composer up jubianchi/async-generator and everything should be ready., (*4)

If you don't want to manually edit your composer.json file, simply run composer require jubianchi/async-generator and you should be ready., (*5)

Testing

Once everything is installed, create a simple PHP file:, (*6)

<?php

//index.php

require_once __DIR__ . '/vendor/autoload.php';

use function jubianchi\async\runtime\{await, all};
use function jubianchi\async\time\{delay};

await(
    all(
        delay(5000, function() { echo 'World!'; }),
        delay(2000, function() { echo 'Hello '; })
    )
);

Run this script using time php index.php: if everything is OK, you should see the word Hello after 2 seconds and World! after 5 seconds:, (*7)

Hello World!

real    0m5.029s
user    0m4.234s
sys     0m0.317s

Notice the whole script took about 5 seconds to complete when the total delay is 7 seconds: this is all the magic behind this library. It allows you to write concurrent tasks with PHP!, (*8)

The Versions

18/03 2017

dev-master

9999999-dev

An async generator runtime for PHP

  Sources   Download

MIT

The Requires

  • php ^7.0.3

 

The Development Requires

by Avatar jubianchi

generator async runtime