As the RFC said.
https://wiki.php.net/rfc/generator-delegation
The defining feature of Generator functions is their support for
suspending execution for later resumption. This capability gives
applications a mechanism to implement asynchronous and concurrent
architectures even in a traditionally single-threaded language like
PHP. With simple userland task scheduling systems interleaved
generators become lightweight threads of execution for concurrent
processing tasks.

I wrote a small test. to see if it really concurrent processing any tasks.
the result looks bad. Still single blocking thread.

<?php

function delayYield()
{
    $delay = mt_rand(1, 5);
    echo "Delay $delay seconds" . PHP_EOL;
    sleep($delay);
    yield date('Y-m-d H:i:s');
}

function demoYield()
{
    yield from delayYield();
    yield from delayYield();
    yield from delayYield();
    return delayYield();
}


foreach (demoYield() as $v) {
    echo $v . PHP_EOL;
}


the executed result:

Delay 3 seconds
2015-12-07 07:04:12
Delay 4 seconds
2015-12-07 07:04:16
Delay 1 seconds
2015-12-07 07:04:17


What is concurrent processing as you know?

http://docs.hhvm.com/hack/async/introduction

HHVM async described well .



Appreciate your time.
----------------------------
Netroby

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to