mirror of
https://github.com/amphp/parallel.git
synced 2025-01-17 20:58:36 +01:00
Do not start global pool until used
This commit is contained in:
parent
ff146bc8ba
commit
d4a2c311ca
@ -25,10 +25,6 @@ function pool(Pool $pool = null): Pool {
|
||||
$pool = new DefaultPool;
|
||||
}
|
||||
|
||||
if (!$pool->isRunning()) {
|
||||
$pool->start();
|
||||
}
|
||||
|
||||
Loop::setState(LOOP_POOL_IDENTIFIER, $pool);
|
||||
return $pool;
|
||||
}
|
||||
@ -41,7 +37,13 @@ function pool(Pool $pool = null): Pool {
|
||||
* @return \Amp\Promise<mixed>
|
||||
*/
|
||||
function enqueue(Task $task): Promise {
|
||||
return pool()->enqueue($task);
|
||||
$pool = pool();
|
||||
|
||||
if (!$pool->isRunning()) {
|
||||
$pool->start();
|
||||
}
|
||||
|
||||
return $pool->enqueue($task);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -81,5 +83,11 @@ function factory(WorkerFactory $factory = null): WorkerFactory {
|
||||
* @return \Amp\Parallel\Worker\Worker
|
||||
*/
|
||||
function get(): Worker {
|
||||
return pool()->get();
|
||||
$pool = pool();
|
||||
|
||||
if (!$pool->isRunning()) {
|
||||
$pool->start();
|
||||
}
|
||||
|
||||
return $pool->get();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user