- timer task shceuled to order goroutine to avoid concurrent problem.

This commit is contained in:
gazebo
2018-07-22 23:11:20 +08:00
parent 52ac5ca64a
commit ae214d38b9
10 changed files with 55 additions and 32 deletions

View File

@@ -10,6 +10,7 @@ import (
"git.rosy.net.cn/baseapi/platformapi/autonavi"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/baseapi/utils/routinepool"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/globals/api"
)
@@ -18,12 +19,17 @@ const (
DefaultOrderCacheTimeout = 24 * time.Hour
)
var (
routinePool *routinepool.Pool
)
type SyncMapWithTimeout struct {
sync.Map
}
func init() {
rand.Seed(time.Now().Unix())
routinePool = routinepool.New(1000, 1000)
}
func (m *SyncMapWithTimeout) StoreWithTimeout(key, value interface{}, timeout time.Duration) {
@@ -142,3 +148,15 @@ func StandardPrice2Int(value float64) int64 {
func IntPrice2StandardString(value int64) string {
return fmt.Sprintf("%.2f", IntPrice2Standard(value))
}
func CallMsgHandler(handler func(), primaryID string) {
routinePool.CallFun(func() {
handler()
}, primaryID)
}
func CallMsgHandlerAsync(handler func(), primaryID string) {
routinePool.CallFunAsync(func() {
handler()
}, primaryID)
}