2016-12-30 02:16:04 +01:00
|
|
|
<?php
|
2015-12-05 06:50:32 +01:00
|
|
|
|
2016-08-23 23:47:40 +02:00
|
|
|
namespace Amp\Parallel\Worker;
|
2016-08-18 18:04:48 +02:00
|
|
|
|
2017-02-18 00:00:24 +01:00
|
|
|
use Amp\Parallel\Threading\Thread;
|
2015-12-05 08:09:42 +01:00
|
|
|
|
2015-12-05 06:50:32 +01:00
|
|
|
/**
|
|
|
|
* The built-in worker factory type.
|
|
|
|
*/
|
2016-08-18 18:04:48 +02:00
|
|
|
class DefaultWorkerFactory implements WorkerFactory {
|
2015-12-05 06:50:32 +01:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*
|
|
|
|
* The type of worker created depends on the extensions available. If multi-threading is enabled, a WorkerThread
|
2017-02-18 00:00:24 +01:00
|
|
|
* 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.
|
2015-12-05 06:50:32 +01:00
|
|
|
*/
|
2016-08-18 18:04:48 +02:00
|
|
|
public function create(): Worker {
|
|
|
|
if (Thread::supported()) {
|
2016-08-23 01:25:19 +02:00
|
|
|
return new WorkerThread;
|
2015-12-05 06:50:32 +01:00
|
|
|
}
|
|
|
|
|
2016-08-23 01:25:19 +02:00
|
|
|
return new WorkerProcess;
|
2015-12-05 06:50:32 +01:00
|
|
|
}
|
|
|
|
}
|