Skip to content

Commit

Permalink
合理性变更
Browse files Browse the repository at this point in the history
  • Loading branch information
yf committed Dec 9, 2018
1 parent 2d551a5 commit 9cda2d2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/Pool/AbstractPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


use EasySwoole\Component\Pool\Exception\PoolEmpty;
use EasySwoole\Component\Pool\Exception\PoolUnRegister;
use Swoole\Coroutine\Channel;

abstract class AbstractPool
Expand Down Expand Up @@ -168,20 +169,25 @@ protected function getPoolConfig():PoolConf
return $this->conf;
}

public function invoke(callable $call,float $timeout = null)
public static function invoke(callable $call,float $timeout = null)
{
$obj = $this->getObj($timeout);
if($obj){
try{
$ret = call_user_func($call,$obj);
$this->recycleObj($obj);
return $ret;
}catch (\Throwable $throwable){
$this->recycleObj($obj);
throw $throwable;
$pool = PoolManager::getInstance()->getPool(static::class);
if($pool instanceof AbstractPool){
$obj = $pool->getObj($timeout);
if($obj){
try{
$ret = call_user_func($call,$obj);
$pool->recycleObj($obj);
return $ret;
}catch (\Throwable $throwable){
$pool->recycleObj($obj);
throw $throwable;
}
}else{
throw new PoolEmpty(static::class." pool is empty");
}
}else{
throw new PoolEmpty(static::class." pool is empty");
throw new PoolUnRegister(static::class." pool is unregister");
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/Pool/Exception/PoolUnRegister.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* Created by PhpStorm.
* User: yf
* Date: 2018/12/9
* Time: 10:07 AM
*/

namespace EasySwoole\Component\Pool\Exception;


class PoolUnRegister extends \Exception
{

}

0 comments on commit 9cda2d2

Please sign in to comment.