Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 126adf0

Browse files
20220419
1 parent 342fa99 commit 126adf0

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

‎go-30/obj_pool_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type ObjPool struct {
2323
bufChan chan *ReusableObj
2424
}
2525

26+
//创建一个对象池
2627
func NewObjPool(numOfObj int) *ObjPool {
2728
objPool := ObjPool{}
2829
//创建的Buffered Channels 指定容量numOfObj
@@ -33,6 +34,7 @@ func NewObjPool(numOfObj int) *ObjPool {
3334
return &objPool
3435
}
3536

37+
//获取对象
3638
func (p *ObjPool) GetObj(timeout time.Duration) (*ReusableObj, error) {
3739
select {
3840
case ret := <-p.bufChan:
@@ -42,6 +44,7 @@ func (p *ObjPool) GetObj(timeout time.Duration) (*ReusableObj, error) {
4244
}
4345
}
4446

47+
//释放对象
4548
func (p *ObjPool) ReleaseObj(obj *ReusableObj) error {
4649
select {
4750
case p.bufChan <- obj:
@@ -53,6 +56,7 @@ func (p *ObjPool) ReleaseObj(obj *ReusableObj) error {
5356
}
5457

5558
func TestObjPool(t *testing.T) {
59+
//创建一个对象池子
5660
pool := NewObjPool(10)
5761
for i := 0; i < 11; i++ {
5862
if v, err := pool.GetObj(time.Second * 1); err != nil {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /