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
|
||||
RegisterCaHandle(c string, a string, handle GinHandlerFunc)
|
||||
GetPid() int
|
||||
AsyncLock(string, *AsyncTask)
|
||||
AsyncUnLock(string)
|
||||
}
|
||||
|
||||
type UserApp interface {
|
||||
@ -81,6 +79,7 @@ type app struct {
|
||||
ormDbHash map[string]*gorm.DB
|
||||
caHandlersMutex sync.RWMutex
|
||||
caHandlers map[string]GinHandlerFunc
|
||||
pendingAsyncTask map[string]map[string][]*LockAsyncTask
|
||||
}
|
||||
|
||||
func (this *app) init(userApp UserApp) {
|
||||
@ -386,14 +385,6 @@ func (this *app) GetPid() int {
|
||||
return this.pid
|
||||
}
|
||||
|
||||
func (this *app) AsyncLock(key string, task *AsyncTask) {
|
||||
|
||||
}
|
||||
|
||||
func (this *app) AsyncUnLock(key string) {
|
||||
|
||||
}
|
||||
|
||||
func parseArgs() (int, int) {
|
||||
args := os.Args[1:]
|
||||
if len(args) <= 0 {
|
||||
|
@ -1,13 +1,24 @@
|
||||
package f5
|
||||
|
||||
import (
|
||||
"q5"
|
||||
)
|
||||
|
||||
type taskLock struct {
|
||||
entry q5.ListHead
|
||||
}
|
||||
|
||||
type AsyncTask struct {
|
||||
status int32
|
||||
cb func(*AsyncTask)
|
||||
succCb func(*AsyncTask)
|
||||
failCb func(*AsyncTask)
|
||||
execTimes int64
|
||||
lockKeys [][]string
|
||||
}
|
||||
|
||||
type LockAsyncTask = AsyncTask
|
||||
|
||||
func (this *AsyncTask) init(cb func(*AsyncTask)) *AsyncTask {
|
||||
this.cb = cb
|
||||
return this
|
||||
@ -61,6 +72,18 @@ func (this *AsyncTask) Continue() *AsyncTask {
|
||||
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 {
|
||||
this.succCb = cb
|
||||
return this
|
||||
@ -72,5 +95,13 @@ func (this *AsyncTask) OnFail(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