Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yf committed Nov 30, 2018
1 parent 38fb502 commit b9dacda
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Pool/AbstractPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,20 @@ public function recycleObj($obj):bool
}
}

public function getObj(float $timeout = 0.1)
public function getObj(float $timeout = 0.1,int $tryTimes = 3)
{
if($tryTimes <= 0){
return null;
}
//懒惰创建模式
$obj = null;
if($this->chan->isEmpty()){
//如果还没有达到最大连接数,则尝试进行创建
if($this->createdNum < $this->max){
$this->createdNum++;
/*
* 创建对象的时候,请加try,尽量不要抛出异常
*/
$obj = $this->createObject();
if(!is_object($obj)){
$this->createdNum--;
Expand Down Expand Up @@ -96,7 +102,7 @@ public function getObj(float $timeout = 0.1)
if($status == false){
$this->unsetObj($obj);
//重新进入对象获取
return $this->getObj($timeout);
return $this->getObj($timeout,$tryTimes - 1);
}
}
return $obj;
Expand Down

0 comments on commit b9dacda

Please sign in to comment.