|
|
@@ -60,7 +60,7 @@ func SendRPC2Notify(req *jsonrpc2.Request) error {
|
|
|
}
|
|
|
|
|
|
// 发送请求, 并等待应答
|
|
|
-func SendRPC2Request(req *jsonrpc2.Request, timeout int /*单位: ms*/) (*jsonrpc2.Response, error) {
|
|
|
+func SendRPC2Request(req *jsonrpc2.Request, timeout time.Duration) (*jsonrpc2.Response, error) {
|
|
|
if req == nil || req.ID == nil {
|
|
|
return nil, fmt.Errorf("invalid request")
|
|
|
}
|
|
|
@@ -80,14 +80,14 @@ func SendRPC2Request(req *jsonrpc2.Request, timeout int /*单位: ms*/) (*jsonrp
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
- timer := time.NewTimer(time.Duration(timeout) * time.Millisecond)
|
|
|
+ timer := time.NewTimer(timeout)
|
|
|
defer timer.Stop()
|
|
|
|
|
|
select {
|
|
|
case resp := <-ch:
|
|
|
return resp, nil
|
|
|
case <-timer.C:
|
|
|
- return nil, fmt.Errorf("request %v timed out after %d ms", id, timeout)
|
|
|
+ return nil, fmt.Errorf("request %v timed out after %v", id, timeout)
|
|
|
}
|
|
|
}
|
|
|
|