1
This commit is contained in:
parent
f60162262a
commit
fbaad6f524
@ -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,6 +143,7 @@ func (this *httpCliMgr) internalSendRequest(
|
|||||||
}
|
}
|
||||||
handle := &httpCliRequestHandleImpl{}
|
handle := &httpCliRequestHandleImpl{}
|
||||||
doFunc := func() {
|
doFunc := func() {
|
||||||
|
if atomic.CompareAndSwapInt32(&handle.state, 0, 1) {
|
||||||
data, err := q5.HttpGet(url, params)
|
data, err := q5.HttpGet(url, params)
|
||||||
if cb == nil {
|
if cb == nil {
|
||||||
return
|
return
|
||||||
@ -153,6 +159,7 @@ func (this *httpCliMgr) internalSendRequest(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
go doFunc()
|
go doFunc()
|
||||||
return handle
|
return handle
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user