mirror of
https://github.com/amphp/parallel.git
synced 2025-02-22 05:42:36 +01:00
31 lines
767 B
PHP
31 lines
767 B
PHP
<?php
|
|
namespace Icicle\Concurrent\Worker;
|
|
|
|
use Icicle\Concurrent\{Forking\Fork, 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 WorkerFork will be created if forking is available, otherwise
|
|
* a WorkerProcess will be created.
|
|
*/
|
|
public function create(): Worker
|
|
{
|
|
if (Thread::enabled()) {
|
|
return new WorkerThread();
|
|
}
|
|
|
|
if (Fork::enabled()) {
|
|
return new WorkerFork();
|
|
}
|
|
|
|
return new WorkerProcess();
|
|
}
|
|
}
|