1
0
mirror of https://github.com/danog/parallel.git synced 2024-11-27 04:44:56 +01:00
parallel/lib/Worker/DefaultWorkerFactory.php
2017-11-10 10:00:04 -06:00

28 lines
817 B
PHP

<?php
namespace Amp\Parallel\Worker;
use Amp\Parallel\Thread\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;
}
}