isRunning()) { $instance->start(); } return $instance; } /** * @coroutine * * Enqueues a task to be executed by the worker pool. * * @param \Icicle\Concurrent\Worker\Task $task The task to enqueue. * * @return \Generator * * @resolve mixed The return value of the task. */ function enqueue(Task $task) { return pool()->enqueue($task); } /** * @param \Icicle\Concurrent\Worker\WorkerFactory|null $factory * * @return \Icicle\Concurrent\Worker\Worker */ function create(WorkerFactory $factory = null) { static $instance; if (null !== $factory) { $instance = $factory; } elseif (null === $instance) { $instance = new DefaultWorkerFactory(); } $worker = $instance->create(); $worker->start(); return $worker; } }