pub fn call(&self, request: T, timeout: Duration) -> Result<U, RpcError> {
        let now = Instant::now();
        while !self.ping(timeout) {
            thread::sleep(Duration::from_millis(1));
            if now.elapsed() > timeout {
                return Err(RpcError::RpcError(String::from(
                    "RPC call timed out while waiting for ping",
                )));
            }
        }

        match self.sender.send_recv(request, timeout) {
            Ok(response) => Ok(response),
            Err(err) => {
                match err.kind() {
                    ErrorKind::Other => {
                        let err_str = err.to_string();
                        lazy_static::lazy_static! {
                            static ref RE: Regex = Regex::new(&format!("{}: ", RPC_ERROR)).unwrap();
                        }

                        if RE.is_match(&err_str) {
                            // there should be two items in the split, where the second one is the
                            // actual string. this should not actually panic.
                            let mut split = RE.split(&err_str);
                            split.next();
                            Err(RpcError::RpcError(split.next().unwrap().to_string()))
                        } else {
                            Err(RpcError::IoError(err))
                        }
                    }
                    _ => Err(RpcError::IoError(err)),
                }
            }
        }
    }
/// Call the RPC and return the response.
///
/// If the types used to initialize the RPC client differ from the RPC server, some very
/// cryptic errors can occur. Since `bincode` is used for serialization, the type of error can
/// differ depending on where the deserialization occurs. In any case, it's important to make
/// sure types are matched properly when creating RPC servers and clients.
Call the RPC and return the response.
If the types used to initialize the RPC client differ from the RPC server, some very
cryptic errors can occur. Since `bincode` is used for serialization, the type of error can
differ depending on where the deserialization occurs. In any case, it's important to make
sure types are matched properly when creating RPC servers and clients.
Call the RPC and return the response . If the types used to initialize the RPC client differ from the RPC server some very cryptic errors can occur . Since ` bincode ` is used for serialization the type of error can differ depending on where the deserialization occurs . In any case it ' s important to make sure types are matched properly when creating RPC servers and clients .
pub fn call(&self, request: T, timeout: Duration) -> Result<U, RpcError> {
        let now = Instant::now();
        while !self.ping(timeout) {
            thread::sleep(Duration::from_millis(1));
            if now.elapsed() > timeout {
                return Err(RpcError::RpcError(String::from(
                    "RPC call timed out while waiting for ping",
                )));
            }
        }
        match self.sender.send_recv(request, timeout) {
            Ok(response) => Ok(response),
            Err(err) => {
                match err.kind() {
                    ErrorKind::Other => {
                        let err_str = err.to_string();
                        lazy_static::lazy_static! {
                            static ref RE: Regex = Regex::new(&format!("{}: ", RPC_ERROR)).unwrap();
                        }
                        if RE.is_match(&err_str) {
                            // there should be two items in the split, where the second one is the
                            // actual string. this should not actually panic.
                            let mut split = RE.split(&err_str);
                            split.next();
                            Err(RpcError::RpcError(split.next().unwrap().to_string()))
                        } else {
                            Err(RpcError::IoError(err))
                        }
                    }
                    _ => Err(RpcError::IoError(err)),
                }
            }
        }
    }
pub fn call ( & self , request : T , timeout : Duration ) -> Result < U , RpcError > { let now = Instant :: now ( ) ; while ! self . ping ( timeout ) { thread :: sleep ( Duration :: from_millis ( 1 ) ) ; if now . elapsed ( ) > timeout { return Err ( RpcError :: RpcError ( String :: from ( " " , ) ) ) ; } } match self . sender . send_recv ( request , timeout ) { Ok ( response ) => Ok ( response ) , Err ( err ) => { match err . kind ( ) { ErrorKind :: Other => { let err_str = err . to_string ( ) ; lazy_static :: lazy_static ! { static ref RE Regex Regex new ( format ( " " RPC_ERROR ) ) unwrap ( ) } if RE . is_match ( & err_str ) { // there should be two items in the split, where the second one is the // actual string. this should not actually panic. let mut split = RE . split ( & err_str ) ; split . next ( ) ; Err ( RpcError :: RpcError ( split . next ( ) . unwrap ( ) . to_string ( ) ) ) } else { Err ( RpcError :: IoError ( err ) ) } } _ => Err ( RpcError :: IoError ( err ) ) , } } } }
Call the RPC and return the response.
Call the RPC and return the response .
&self
request
T
timeout
Duration
&self
request
T
timeout
Duration