From da6b9ac4bbea56afd03e792c8fb3544a6a821ff5 Mon Sep 17 00:00:00 2001 From: john Date: Mon, 30 Jul 2018 11:22:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E6=8E=89gpool=E4=B8=ADmath.MAXINT64?= =?UTF-8?q?=E5=B8=B8=E9=87=8F=E7=9A=84=E4=BD=BF=E7=94=A8=EF=BC=8C=E4=BB=A5?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Dint64=E5=88=B0int=E7=B1=BB=E5=9E=8B=E7=9A=84?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E9=94=99=E8=AF=AF=EF=BC=8C=E5=85=BC=E5=AE=B9?= =?UTF-8?q?32=E4=BD=8D=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- g/container/gpool/gpool.go | 19 ++++++++++--------- geg/other/test.go | 7 +++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/g/container/gpool/gpool.go b/g/container/gpool/gpool.go index 5d2a18449..4c96dce7c 100644 --- a/g/container/gpool/gpool.go +++ b/g/container/gpool/gpool.go @@ -13,7 +13,6 @@ import ( "gitee.com/johng/gf/g/os/gtime" "gitee.com/johng/gf/g/container/glist" "gitee.com/johng/gf/g/container/gtype" - "math" ) // 对象池 @@ -36,9 +35,6 @@ type poolItem struct { // expire = 0表示不过期,expire < 0表示使用完立即回收,expire > 0表示超时回收 // 注意过期时间单位为**毫秒** func New(expire int, newFunc...func() (interface{}, error)) *Pool { - if expire == 0 { - expire = math.MaxInt64 - } r := &Pool { list : glist.New(), closed : gtype.NewBool(), @@ -57,11 +53,16 @@ func (p *Pool) SetExpireFunc(expireFunc func(interface{})) { } // 放一个临时对象到池中 -func (p *Pool) Put(item interface{}) { - p.list.PushBack(&poolItem { - expire : gtime.Millisecond() + p.Expire, - value : item, - }) +func (p *Pool) Put(value interface{}) { + item := &poolItem { + value : value, + } + if p.Expire == 0 { + item.expire = 0 + } else { + item.expire = gtime.Millisecond() + p.Expire + } + p.list.PushBack(item) } // 从池中获得一个临时对象 diff --git a/geg/other/test.go b/geg/other/test.go index b599cbbee..48f757886 100644 --- a/geg/other/test.go +++ b/geg/other/test.go @@ -1,11 +1,10 @@ package main import ( - "gitee.com/johng/gf/g/os/gfile" + "fmt" + "math" ) func main() { - gfile.PutContentsAppend("/tmp/test", "1") - gfile.PutContentsAppend("/tmp/test", "2") - gfile.PutContentsAppend("/tmp/test", "3") + fmt.Println(int(math.MaxInt64)) } \ No newline at end of file