2015-07-09 08:35:34 +02:00
|
|
|
<?php
|
|
|
|
require dirname(__DIR__).'/vendor/autoload.php';
|
|
|
|
|
2015-07-10 09:23:08 +02:00
|
|
|
use Icicle\Loop;
|
2015-07-09 08:35:34 +02:00
|
|
|
use Icicle\Concurrent\Forking\ForkContext;
|
|
|
|
|
2015-07-09 20:13:20 +02:00
|
|
|
class Test extends ForkContext
|
|
|
|
{
|
|
|
|
public function run()
|
|
|
|
{
|
2015-07-10 09:23:08 +02:00
|
|
|
print "Child sleeping for 5 seconds...\n";
|
|
|
|
sleep(3);
|
|
|
|
|
|
|
|
$this->synchronized(function () {
|
|
|
|
$this->data = 'progress';
|
|
|
|
});
|
|
|
|
|
|
|
|
sleep(2);
|
2015-07-09 20:13:20 +02:00
|
|
|
}
|
|
|
|
}
|
2015-07-09 08:35:34 +02:00
|
|
|
|
2015-07-09 20:13:20 +02:00
|
|
|
$context = new Test();
|
2015-07-10 09:23:08 +02:00
|
|
|
$context->data = 'blank';
|
|
|
|
$context->start();
|
|
|
|
$context->join()->then(function () {
|
|
|
|
print "Context done!\n";
|
|
|
|
Loop\stop();
|
2015-07-09 20:13:20 +02:00
|
|
|
});
|
2015-07-09 08:35:34 +02:00
|
|
|
|
2015-07-10 09:23:08 +02:00
|
|
|
Loop\periodic(1, function () use ($context) {
|
2015-07-09 08:35:34 +02:00
|
|
|
static $i;
|
|
|
|
$i = $i + 1 ?: 1;
|
|
|
|
print "Demonstrating how alive the parent is for the {$i}th time.\n";
|
2015-07-10 09:23:08 +02:00
|
|
|
|
|
|
|
$context->synchronized(function ($context) {
|
|
|
|
printf("Context data: '%s'\n", $context->data);
|
|
|
|
});
|
2015-07-09 08:35:34 +02:00
|
|
|
});
|
|
|
|
|
2015-07-10 09:23:08 +02:00
|
|
|
Loop\run();
|