1
0
mirror of https://github.com/danog/parallel.git synced 2025-01-22 22:11:11 +01:00

Add example for worker thread

This commit is contained in:
coderstephen 2015-08-22 16:13:52 -05:00
parent 3673798c6d
commit bc608e5147

27
examples/worker-thread.php Executable file
View File

@ -0,0 +1,27 @@
#!/usr/bin/env php
<?php
require dirname(__DIR__).'/vendor/autoload.php';
use Icicle\Concurrent\Worker\TaskInterface;
use Icicle\Concurrent\Worker\WorkerThread;
use Icicle\Coroutine;
use Icicle\Loop;
class HelloTask implements TaskInterface
{
public function run()
{
echo "Hello!\n";
return 42;
}
}
Coroutine\create(function () {
$worker = new WorkerThread();
$worker->start();
$returnValue = (yield $worker->enqueue(new HelloTask()));
yield $worker->shutdown();
});
Loop\run();