niujiuru 1 ماه پیش
والد
کامیت
3259735253
1فایلهای تغییر یافته به همراه3 افزوده شده و 3 حذف شده
  1. 3 3
      mcu_ctrl_board/proc_rpc2.go

+ 3 - 3
mcu_ctrl_board/proc_rpc2.go

@@ -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 {
 	if req == nil || req.ID == nil {
 		return nil, fmt.Errorf("invalid request")
 		return nil, fmt.Errorf("invalid request")
 	}
 	}
@@ -80,14 +80,14 @@ func SendRPC2Request(req *jsonrpc2.Request, timeout int /*单位: ms*/) (*jsonrp
 		return nil, err
 		return nil, err
 	}
 	}
 
 
-	timer := time.NewTimer(time.Duration(timeout) * time.Millisecond)
+	timer := time.NewTimer(timeout)
 	defer timer.Stop()
 	defer timer.Stop()
 
 
 	select {
 	select {
 	case resp := <-ch:
 	case resp := <-ch:
 		return resp, nil
 		return resp, nil
 	case <-timer.C:
 	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)
 	}
 	}
 }
 }