21 declare(strict_types=1);
30 private $workerFactory;
32 private $workers = [];
47 public function __construct(callable $workerFactory,
int $workerLimit){
48 $this->workerFactory = $workerFactory;
49 $this->workerLimit = $workerLimit;
55 private function addWorker() : void{
56 $this->workers[] = ($this->workerFactory)($this->bufferSend, $this->bufferRecv);
59 public function join() : void{
60 foreach($this->workers as $worker){
66 foreach($this->workers as $worker){
67 $worker->stopRunning();
71 public function addQuery(
int $queryId,
int $mode,
string $query, array $params) : void{
72 $this->bufferSend->scheduleQuery($queryId, $mode, $query, $params);
75 foreach($this->workers as $worker){
76 if(!$worker->isWorking()){
80 if(
count($this->workers) < $this->workerLimit){
86 while($this->bufferRecv->fetchResult($queryId, $result)){
87 if(!isset($callbacks[$queryId])){
91 $callbacks[$queryId]($result);
92 unset($callbacks[$queryId]);
97 return $this->workers[0]->connCreated();
101 return $this->workers[0]->hasConnError();
105 return $this->workers[0]->getConnError();
109 return $this->bufferSend->count() / (float) $this->workerLimit;
addQuery(int $queryId, int $mode, string $query, array $params)
readResults(array &$callbacks)
__construct(callable $workerFactory, int $workerLimit)