forked from yuxh/gearman-go
Remove lastcall.
This commit is contained in:
parent
5c665de2d6
commit
f2f0349d2d
@ -18,12 +18,12 @@ var (
|
||||
type Client struct {
|
||||
sync.Mutex
|
||||
|
||||
net, addr, lastcall string
|
||||
respHandler *responseHandlerMap
|
||||
innerHandler *responseHandlerMap
|
||||
in chan *Response
|
||||
conn net.Conn
|
||||
rw *bufio.ReadWriter
|
||||
net, addr string
|
||||
respHandler *responseHandlerMap
|
||||
innerHandler *responseHandlerMap
|
||||
in chan *Response
|
||||
conn net.Conn
|
||||
rw *bufio.ReadWriter
|
||||
|
||||
ResponseTimeout time.Duration // response timeout for do() in ms
|
||||
|
||||
@ -171,12 +171,7 @@ func (client *Client) processLoop() {
|
||||
for resp := range client.in {
|
||||
switch resp.DataType {
|
||||
case dtError:
|
||||
if client.lastcall != "" {
|
||||
resp = client.handleInner(client.lastcall, resp)
|
||||
client.lastcall = ""
|
||||
} else {
|
||||
client.err(getError(resp.Data))
|
||||
}
|
||||
client.err(getError(resp.Data))
|
||||
case dtStatusRes:
|
||||
resp = client.handleInner("s"+resp.Handle, resp)
|
||||
case dtJobCreated:
|
||||
@ -228,7 +223,6 @@ func (client *Client) do(funcname string, data []byte,
|
||||
var result = make(chan handleOrError, 1)
|
||||
client.Lock()
|
||||
defer client.Unlock()
|
||||
client.lastcall = "c"
|
||||
client.innerHandler.put("c", func(resp *Response) {
|
||||
if resp.DataType == dtError {
|
||||
err = getError(resp.Data)
|
||||
@ -243,7 +237,6 @@ func (client *Client) do(funcname string, data []byte,
|
||||
req.DataType = flag
|
||||
if err = client.write(req); err != nil {
|
||||
client.innerHandler.remove("c")
|
||||
client.lastcall = ""
|
||||
return
|
||||
}
|
||||
var timer = time.After(client.ResponseTimeout * time.Millisecond)
|
||||
@ -252,7 +245,6 @@ func (client *Client) do(funcname string, data []byte,
|
||||
return ret.handle, ret.err
|
||||
case <-timer:
|
||||
client.innerHandler.remove("c")
|
||||
client.lastcall = ""
|
||||
return "", ErrLostConn
|
||||
}
|
||||
return
|
||||
@ -308,7 +300,6 @@ func (client *Client) Status(handle string) (status *Status, err error) {
|
||||
}
|
||||
var mutex sync.Mutex
|
||||
mutex.Lock()
|
||||
client.lastcall = "s" + handle
|
||||
client.innerHandler.put("s"+handle, func(resp *Response) {
|
||||
defer mutex.Unlock()
|
||||
var err error
|
||||
@ -339,7 +330,6 @@ func (client *Client) Echo(data []byte) (echo []byte, err error) {
|
||||
req := getRequest()
|
||||
req.DataType = dtEchoReq
|
||||
req.Data = data
|
||||
client.lastcall = "e"
|
||||
client.write(req)
|
||||
mutex.Lock()
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user