mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
move gtime.SetTimeout>ime.SetInterval to gtimer
This commit is contained in:
@ -47,23 +47,23 @@ func (bs *dbBase) convertValue(fieldValue interface{}, fieldType string) interfa
|
||||
default:
|
||||
// 自动识别类型, 以便默认支持更多数据库类型
|
||||
switch {
|
||||
case strings.Contains(t, "int"):
|
||||
return gconv.Int(fieldValue)
|
||||
case strings.Contains(t, "int"):
|
||||
return gconv.Int(fieldValue)
|
||||
|
||||
case strings.Contains(t, "text") || strings.Contains(t, "char"):
|
||||
return gconv.String(fieldValue)
|
||||
case strings.Contains(t, "text") || strings.Contains(t, "char"):
|
||||
return gconv.String(fieldValue)
|
||||
|
||||
case strings.Contains(t, "float") || strings.Contains(t, "double"):
|
||||
return gconv.Float64(fieldValue)
|
||||
case strings.Contains(t, "float") || strings.Contains(t, "double"):
|
||||
return gconv.Float64(fieldValue)
|
||||
|
||||
case strings.Contains(t, "bool"):
|
||||
return gconv.Bool(fieldValue)
|
||||
case strings.Contains(t, "bool"):
|
||||
return gconv.Bool(fieldValue)
|
||||
|
||||
case strings.Contains(t, "binary") || strings.Contains(t, "blob"):
|
||||
return gconv.Bytes(fieldValue)
|
||||
case strings.Contains(t, "binary") || strings.Contains(t, "blob"):
|
||||
return gconv.Bytes(fieldValue)
|
||||
|
||||
default:
|
||||
return gconv.String(fieldValue)
|
||||
default:
|
||||
return gconv.String(fieldValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ import (
|
||||
"gitee.com/johng/gf/g/os/gfile"
|
||||
"gitee.com/johng/gf/g/os/glog"
|
||||
"gitee.com/johng/gf/g/os/gproc"
|
||||
"gitee.com/johng/gf/g/os/gtime"
|
||||
"gitee.com/johng/gf/g/os/gtimer"
|
||||
"gitee.com/johng/gf/g/util/gconv"
|
||||
"gitee.com/johng/gf/g/util/gregex"
|
||||
"gitee.com/johng/gf/third/github.com/gorilla/websocket"
|
||||
@ -251,7 +251,7 @@ func (s *Server) Start() error {
|
||||
|
||||
// 如果是子进程,那么服务开启后通知父进程销毁
|
||||
if gproc.IsChild() {
|
||||
gtime.SetTimeout(2*time.Second, func() {
|
||||
gtimer.SetTimeout(2*time.Second, func() {
|
||||
if err := gproc.Send(gproc.PPid(), []byte("exit"), gADMIN_GPROC_COMM_GROUP); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -271,7 +271,7 @@ func (s *Server) Start() error {
|
||||
func (s *Server) DumpRoutesMap() {
|
||||
if s.config.DumpRouteMap && len(s.routesMap) > 0 {
|
||||
// (等待一定时间后)当所有框架初始化信息打印完毕之后才打印路由表信息
|
||||
gtime.SetTimeout(50*time.Millisecond, func() {
|
||||
gtimer.SetTimeout(50*time.Millisecond, func() {
|
||||
glog.Header(false).Println(fmt.Sprintf("\n%s\n", s.GetRouteMap()))
|
||||
})
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
package ghttp
|
||||
|
||||
import (
|
||||
"gitee.com/johng/gf/g/os/gtimer"
|
||||
"strings"
|
||||
"gitee.com/johng/gf/g/os/gview"
|
||||
"gitee.com/johng/gf/g/os/gproc"
|
||||
@ -251,7 +252,7 @@ func restartWebServers(signal string, newExeFilePath...string) error {
|
||||
forkRestartProcess(newExeFilePath...)
|
||||
} else {
|
||||
// 非终端信号下,异步1秒后再执行重启,目的是让接口能够正确返回结果,否则接口会报错(因为web server关闭了)
|
||||
gtime.SetTimeout(time.Second, func() {
|
||||
gtimer.SetTimeout(time.Second, func() {
|
||||
forcedlyCloseWebServers()
|
||||
forkRestartProcess(newExeFilePath...)
|
||||
})
|
||||
@ -284,7 +285,7 @@ func shutdownWebServers(signal string) {
|
||||
} else {
|
||||
glog.Printfln("%d: server shutting down by web admin", gproc.Pid())
|
||||
// 非终端信号下,异步1秒后再执行关闭,目的是让接口能够正确返回结果,否则接口会报错(因为web server关闭了)
|
||||
gtime.SetTimeout(time.Second, func() {
|
||||
gtimer.SetTimeout(time.Second, func() {
|
||||
forcedlyCloseWebServers()
|
||||
doneChan <- struct{}{}
|
||||
})
|
||||
|
||||
@ -75,27 +75,6 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
// 类似与js中的SetTimeout,一段时间后执行回调函数
|
||||
func SetTimeout(t time.Duration, callback func()) {
|
||||
go func() {
|
||||
time.Sleep(t)
|
||||
callback()
|
||||
}()
|
||||
}
|
||||
|
||||
// 类似与js中的SetInterval,每隔一段时间后执行回调函数,当回调函数返回true,那么继续执行,否则终止执行,该方法是异步的
|
||||
// 注意:由于采用的是循环而不是递归操作,因此间隔时间将会以上一次回调函数执行完成的时间来计算
|
||||
func SetInterval(t time.Duration, callback func() bool) {
|
||||
go func() {
|
||||
for {
|
||||
time.Sleep(t)
|
||||
if !callback() {
|
||||
break
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// 设置当前进程全局的默认时区,如: Asia/Shanghai
|
||||
func SetTimeZone(zone string) error {
|
||||
location, err := time.LoadLocation(zone)
|
||||
|
||||
@ -33,6 +33,17 @@ var (
|
||||
defaultTimer = New(gDEFAULT_SLOT_NUMBER, gDEFAULT_WHEEL_INTERVAL, gDEFAULT_WHEEL_LEVEL)
|
||||
)
|
||||
|
||||
// 类似与js中的SetTimeout,一段时间后执行回调函数
|
||||
func SetTimeout(delay time.Duration, job JobFunc) {
|
||||
AddOnce(delay, job)
|
||||
}
|
||||
|
||||
// 类似与js中的SetInterval,每隔一段时间后执行回调函数,当回调函数返回true,那么继续执行,否则终止执行,该方法是异步的
|
||||
// 注意:由于采用的是循环而不是递归操作,因此间隔时间将会以上一次回调函数执行完成的时间来计算
|
||||
func SetInterval(interval time.Duration, job JobFunc) {
|
||||
Add(interval, job)
|
||||
}
|
||||
|
||||
// 添加执行方法,可以给定名字,以便于后续执行删除
|
||||
func Add(interval time.Duration, job JobFunc) *Entry {
|
||||
return defaultTimer.Add(interval, job)
|
||||
|
||||
Reference in New Issue
Block a user