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 (
"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,6 +143,7 @@ func (this *httpCliMgr) internalSendRequest(
}
handle := &httpCliRequestHandleImpl{}
doFunc := func() {
if atomic.CompareAndSwapInt32(&handle.state, 0, 1) {
data, err := q5.HttpGet(url, params)
if cb == nil {
return
@ -153,6 +159,7 @@ func (this *httpCliMgr) internalSendRequest(
})
}
}
}
go doFunc()
return handle
}