ResponseCode int
Respon []byte
UsedTime time.Duration
- Cancel chan interface{}
+
+ cancelOpen bool
+ cancel chan interface{}
sync.Mutex
}
if _val.Timeout==0{_val.Timeout=3}
for ;_val.Retry>=0;_val.Retry-- {
- returnErr=this.Reqf_1(_val)
- if returnErr==nil {break}
+ returnErr=this.Reqf_1(_val)
+ select {
+ case <- this.cancel://cancel
+ break
+ default:
+ if returnErr==nil {break}
+ }
time.Sleep(time.Duration(_val.SleepTime)*time.Millisecond)
}
req = req.WithContext(cx)
go func(){
- this.Cancel = make(chan interface{})
- <- this.Cancel
+ this.cancel = make(chan interface{})
+ this.cancelOpen = true
+ <- this.cancel
cancel()
}()
this.UsedTime=time.Since(beginTime)
return nil
+}
+
+func (t *req) Close(){
+ if !t.cancelOpen {return}
+ select {
+ case <- t.cancel://had close
+ return
+ default:
+ close(t.cancel)
+ t.cancelOpen = false
+ }
}
\ No newline at end of file