1
This commit is contained in:
parent
178d811f9a
commit
01ba77f7ae
11
app.go
11
app.go
@ -39,8 +39,6 @@ type App interface {
|
|||||||
GetOrmDb(string) *gorm.DB
|
GetOrmDb(string) *gorm.DB
|
||||||
RegisterCaHandle(c string, a string, handle GinHandlerFunc)
|
RegisterCaHandle(c string, a string, handle GinHandlerFunc)
|
||||||
GetPid() int
|
GetPid() int
|
||||||
AsyncLock(string, *AsyncTask)
|
|
||||||
AsyncUnLock(string)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserApp interface {
|
type UserApp interface {
|
||||||
@ -81,6 +79,7 @@ type app struct {
|
|||||||
ormDbHash map[string]*gorm.DB
|
ormDbHash map[string]*gorm.DB
|
||||||
caHandlersMutex sync.RWMutex
|
caHandlersMutex sync.RWMutex
|
||||||
caHandlers map[string]GinHandlerFunc
|
caHandlers map[string]GinHandlerFunc
|
||||||
|
pendingAsyncTask map[string]map[string][]*LockAsyncTask
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *app) init(userApp UserApp) {
|
func (this *app) init(userApp UserApp) {
|
||||||
@ -386,14 +385,6 @@ func (this *app) GetPid() int {
|
|||||||
return this.pid
|
return this.pid
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *app) AsyncLock(key string, task *AsyncTask) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *app) AsyncUnLock(key string) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseArgs() (int, int) {
|
func parseArgs() (int, int) {
|
||||||
args := os.Args[1:]
|
args := os.Args[1:]
|
||||||
if len(args) <= 0 {
|
if len(args) <= 0 {
|
||||||
|
@ -1,13 +1,24 @@
|
|||||||
package f5
|
package f5
|
||||||
|
|
||||||
|
import (
|
||||||
|
"q5"
|
||||||
|
)
|
||||||
|
|
||||||
|
type taskLock struct {
|
||||||
|
entry q5.ListHead
|
||||||
|
}
|
||||||
|
|
||||||
type AsyncTask struct {
|
type AsyncTask struct {
|
||||||
status int32
|
status int32
|
||||||
cb func(*AsyncTask)
|
cb func(*AsyncTask)
|
||||||
succCb func(*AsyncTask)
|
succCb func(*AsyncTask)
|
||||||
failCb func(*AsyncTask)
|
failCb func(*AsyncTask)
|
||||||
execTimes int64
|
execTimes int64
|
||||||
|
lockKeys [][]string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type LockAsyncTask = AsyncTask
|
||||||
|
|
||||||
func (this *AsyncTask) init(cb func(*AsyncTask)) *AsyncTask {
|
func (this *AsyncTask) init(cb func(*AsyncTask)) *AsyncTask {
|
||||||
this.cb = cb
|
this.cb = cb
|
||||||
return this
|
return this
|
||||||
@ -61,6 +72,18 @@ func (this *AsyncTask) Continue() *AsyncTask {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *AsyncTask) do() *AsyncTask {
|
||||||
|
if !this.IsRunning() {
|
||||||
|
panic("task is not runing")
|
||||||
|
}
|
||||||
|
GetApp().RegisterMainThreadCb(
|
||||||
|
func () {
|
||||||
|
this.cb(this)
|
||||||
|
this.execTimes += 1
|
||||||
|
})
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
func (this *AsyncTask) OnSucc(cb func(*AsyncTask)) *AsyncTask {
|
func (this *AsyncTask) OnSucc(cb func(*AsyncTask)) *AsyncTask {
|
||||||
this.succCb = cb
|
this.succCb = cb
|
||||||
return this
|
return this
|
||||||
@ -72,5 +95,13 @@ func (this *AsyncTask) OnFail(cb func(*AsyncTask)) *AsyncTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewAsyncTask(cb func(*AsyncTask)) *AsyncTask {
|
func NewAsyncTask(cb func(*AsyncTask)) *AsyncTask {
|
||||||
return new(AsyncTask).init(cb).Continue()
|
p := new(AsyncTask)
|
||||||
|
p.lockKeys = [][]string{}
|
||||||
|
return p.init(cb).Continue()
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewLockAsyncTask(keys [][]string, cb func(*LockAsyncTask)) *LockAsyncTask {
|
||||||
|
p := new(AsyncTask)
|
||||||
|
p.lockKeys = [][]string{}
|
||||||
|
return p.init(cb).Continue()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user