去掉gpool中math.MAXINT64常量的使用,以修复int64到int类型的转换错误,兼容32位系统

This commit is contained in:
john 2018-07-30 11:22:21 +08:00
parent 6dc3b763c5
commit da6b9ac4bb
2 changed files with 13 additions and 13 deletions

View File

@ -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)
}
// 从池中获得一个临时对象

View File

@ -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))
}