1
0
mirror of https://github.com/danog/parallel.git synced 2024-11-27 12:54:55 +01:00
parallel/lib/Worker/DefaultWorkerFactory.php
2017-02-17 17:00:24 -06:00

28 lines
820 B
PHP

<?php
namespace Amp\Parallel\Worker;
use Amp\Parallel\Threading\Thread;
/**
* The built-in worker factory type.
*/
class DefaultWorkerFactory implements WorkerFactory {
/**
* {@inheritdoc}
*
* The type of worker created depends on the extensions available. If multi-threading is enabled, a WorkerThread
* will be created. If threads are not available a WorkerProcess will be created.
*
* \Amp\Parallel\Forking\WorkerFork is not used in the default factory since forking a process for workers is very
* sensitive to timing and process state and should be used only by the application designer if desired.
*/
public function create(): Worker {
if (Thread::supported()) {
return new WorkerThread;
}
return new WorkerProcess;
}
}