isRunning()) { $instance->start(); } return $instance; } /** * Enqueues a task to be executed by the global worker pool. * * @param \Amp\Concurrent\Worker\Task $task The task to enqueue. * * @return \Interop\Async\Awaitable */ function enqueue(Task $task): Awaitable { return pool()->enqueue($task); } /** * Creates a worker using the global worker factory. * * @return \Amp\Concurrent\Worker\Worker */ function create(): Worker { $worker = factory()->create(); $worker->start(); return $worker; } /** * Gets or sets the global worker factory. * * @param \Amp\Concurrent\Worker\WorkerFactory|null $factory * * @return \Amp\Concurrent\Worker\WorkerFactory */ function factory(WorkerFactory $factory = null): WorkerFactory { static $instance; if (null !== $factory) { $instance = $factory; } elseif (null === $instance) { $instance = new DefaultWorkerFactory(); } return $instance; } /** * Gets a worker from the global worker pool. * * @return \Amp\Concurrent\Worker\Worker */ function get(): Worker { return pool()->get(); }