This commit is contained in:
aozhiwei 2024-03-21 15:29:32 +08:00
parent f60162262a
commit fbaad6f524

View File

@ -2,6 +2,7 @@ package f5
import ( import (
"q5" "q5"
"sync/atomic"
) )
/* /*
@ -23,7 +24,8 @@ type HttpCliRequestHandle interface {
} }
type httpCliRequestHandleImpl struct { type httpCliRequestHandleImpl struct {
state int32 //-1: cancel 0:pending 1:started
cancelCount int32
} }
type HttpCliResponse interface { type HttpCliResponse interface {
@ -44,7 +46,10 @@ type httpCliMgr struct {
} }
func (this *httpCliRequestHandleImpl) Cancel() bool { 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() { func (this *httpCliMgr) init() {
@ -138,19 +143,21 @@ func (this *httpCliMgr) internalSendRequest(
} }
handle := &httpCliRequestHandleImpl{} handle := &httpCliRequestHandleImpl{}
doFunc := func() { doFunc := func() {
data, err := q5.HttpGet(url, params) if atomic.CompareAndSwapInt32(&handle.state, 0, 1) {
if cb == nil { data, err := q5.HttpGet(url, params)
return if cb == nil {
} return
rsp := new(httpCliResponse) }
rsp.init(data, err) rsp := new(httpCliResponse)
if style == GO_STYLE_REQUEST { rsp.init(data, err)
cb(rsp) if style == GO_STYLE_REQUEST {
} else { cb(rsp)
_app.AddIMMsg(IM_HTTP_CLI_MGR_RESPONSE, []interface{}{ } else {
cb, _app.AddIMMsg(IM_HTTP_CLI_MGR_RESPONSE, []interface{}{
rsp, cb,
}) rsp,
})
}
} }
} }
go doFunc() go doFunc()