-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a17fab1
commit ce362d1
Showing
7 changed files
with
252 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,118 @@ | ||
# abstractInterface | ||
# PoolInterface | ||
|
||
``` | ||
use EasySwoole\Component\Pool\PoolManager; | ||
use EasySwoole\Component\Pool\TraitObjectInvoker; | ||
use EasySwoole\Utility\Random; | ||
use EasySwoole\Component\Pool\AbstractPoolObject; | ||
use EasySwoole\Component\Pool\PoolObjectInterface; | ||
use EasySwoole\Component\Pool\AbstractPool; | ||
class test | ||
{ | ||
public $id; | ||
function __construct() | ||
{ | ||
$this->id = Random::character(8); | ||
} | ||
function fuck(){ | ||
var_dump('this is fuck at class:'.static::class.'@id:'.$this->id); | ||
} | ||
} | ||
class test2 extends test implements PoolObjectInterface | ||
{ | ||
function objectRestore() | ||
{ | ||
var_dump('this is objectRestore at class:'.static::class.'@id:'.$this->id); | ||
} | ||
function gc() | ||
{ | ||
// TODO: Implement gc() method. | ||
} | ||
function beforeUse(): bool | ||
{ | ||
// TODO: Implement beforeUse() method. | ||
return true; | ||
} | ||
} | ||
class testPool extends AbstractPool | ||
{ | ||
protected function createObject() | ||
{ | ||
// TODO: Implement createObject() method. | ||
return new test(); | ||
} | ||
} | ||
class testPool2 extends AbstractPool | ||
{ | ||
protected function createObject() | ||
{ | ||
// TODO: Implement createObject() method. | ||
return new test2(); | ||
} | ||
} | ||
class test3 extends test | ||
{ | ||
use TraitObjectInvoker; | ||
} | ||
class test4 extends AbstractPoolObject | ||
{ | ||
function finalFuck() | ||
{ | ||
var_dump('final fuck'); | ||
} | ||
function objectRestore() | ||
{ | ||
var_dump('final objectRestore'); | ||
} | ||
} | ||
//cli下关闭pool的自动定时检查 | ||
PoolManager::getInstance()->getDefaultConfig()->setIntervalCheckTime(0); | ||
go(function (){ | ||
go(function (){ | ||
$object = PoolManager::getInstance()->getPool(test::class)->getObj(); | ||
$object->fuck(); | ||
PoolManager::getInstance()->getPool(test::class)->recycleObj($object); | ||
}); | ||
go(function (){ | ||
testPool::invoke(function (test $test){ | ||
$test->fuck(); | ||
}); | ||
}); | ||
go(function (){ | ||
testPool2::invoke(function (test2 $test){ | ||
$test->fuck(); | ||
}); | ||
}); | ||
go(function (){ | ||
test3::invoke(function (test3 $test3){ | ||
$test3->fuck(); | ||
}); | ||
}); | ||
go(function (){ | ||
$object = PoolManager::getInstance()->getPool(test4::class)->getObj(); | ||
$object->finalFuck(); | ||
PoolManager::getInstance()->getPool(test4::class)->recycleObj($object); | ||
}); | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,9 @@ function beforeUse():bool | |
{ | ||
return true; | ||
} | ||
|
||
function objectRestore() | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.