astaxie / build-web-application-with-golang

A golang ebook intro how to build a web with golang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

session销毁部分的time.AfterFunc函数问题

jking412 opened this issue · comments

func (manager *Manager) GC() {
	manager.lock.Lock()
	defer manager.lock.Unlock()
	time.AfterFunc(time.Duration(manager.maxLifeTime), func() { manager.provider.SessionGC(manager.maxLifeTime) })
}

time.AfterFunc第一个时间参数的单位是纳秒,根据上下文信息,这里是否应该乘上time.Second,如下所示

func (manager *Manager) GC() {
	manager.lock.Lock()
	defer manager.lock.Unlock()
	time.AfterFunc(time.Duration(manager.maxLifeTime)*time.Second, func() { manager.provider.SessionGC(manager.maxLifeTime) })
}