1
This commit is contained in:
parent
f60162262a
commit
fbaad6f524
@ -2,6 +2,7 @@ package f5
|
||||
|
||||
import (
|
||||
"q5"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
/*
|
||||
@ -23,7 +24,8 @@ type HttpCliRequestHandle interface {
|
||||
}
|
||||
|
||||
type httpCliRequestHandleImpl struct {
|
||||
|
||||
state int32 //-1: cancel 0:pending 1:started
|
||||
cancelCount int32
|
||||
}
|
||||
|
||||
type HttpCliResponse interface {
|
||||
@ -44,7 +46,10 @@ type httpCliMgr struct {
|
||||
}
|
||||
|
||||
func (this *httpCliRequestHandleImpl) Cancel() bool {
|
||||
return true
|
||||
ok := atomic.CompareAndSwapInt32(&this.state, 0, -1) ||
|
||||
atomic.CompareAndSwapInt32(&this.state, -1, -1)
|
||||
atomic.AddInt32(&this.cancelCount, 1)
|
||||
return ok
|
||||
}
|
||||
|
||||
func (this *httpCliMgr) init() {
|
||||
@ -138,19 +143,21 @@ func (this *httpCliMgr) internalSendRequest(
|
||||
}
|
||||
handle := &httpCliRequestHandleImpl{}
|
||||
doFunc := func() {
|
||||
data, err := q5.HttpGet(url, params)
|
||||
if cb == nil {
|
||||
return
|
||||
}
|
||||
rsp := new(httpCliResponse)
|
||||
rsp.init(data, err)
|
||||
if style == GO_STYLE_REQUEST {
|
||||
cb(rsp)
|
||||
} else {
|
||||
_app.AddIMMsg(IM_HTTP_CLI_MGR_RESPONSE, []interface{}{
|
||||
cb,
|
||||
rsp,
|
||||
})
|
||||
if atomic.CompareAndSwapInt32(&handle.state, 0, 1) {
|
||||
data, err := q5.HttpGet(url, params)
|
||||
if cb == nil {
|
||||
return
|
||||
}
|
||||
rsp := new(httpCliResponse)
|
||||
rsp.init(data, err)
|
||||
if style == GO_STYLE_REQUEST {
|
||||
cb(rsp)
|
||||
} else {
|
||||
_app.AddIMMsg(IM_HTTP_CLI_MGR_RESPONSE, []interface{}{
|
||||
cb,
|
||||
rsp,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
go doFunc()
|
||||
|
Loading…
x
Reference in New Issue
Block a user