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:
parent
3673798c6d
commit
bc608e5147
27
examples/worker-thread.php
Executable file
27
examples/worker-thread.php
Executable 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();
|
Loading…
x
Reference in New Issue
Block a user