pub fn block_on<F>(&self, f: F, timeout: Option<Duration>) -> Result<F::Output>
    where
        F: Future + Send + 'static,
        F::Output: Send + 'static,
    {
        let (tx, rx) = channel();
        let _jh = self.spawn(async move {
            let r = f.await;
            let _ = tx.send(r);
        });
        let reply = match timeout {
            Some(to) => rx
                .recv_timeout(to)
                .map_err(|timeout_err| ErrorCode::Timeout(timeout_err.to_string()))?,
            None => rx.recv().map_err(ErrorCode::from_std_error)?,
        };
        Ok(reply)
    }
// Poor man's runtime::block_on
// This mainly used for make async function to sync.
Poor man's runtime::block_on
This mainly used for make async function to sync.
Poor man ' s runtime :: block_on This mainly used for make async function to sync .
pub fn block_on<F>(&self, f: F, timeout: Option<Duration>) -> Result<F::Output>
    where
        F: Future + Send + 'static,
        F::Output: Send + 'static,
    {
        let (tx, rx) = channel();
        let _jh = self.spawn(async move {
            let r = f.await;
            let _ = tx.send(r);
        });
        let reply = match timeout {
            Some(to) => rx
                .recv_timeout(to)
                .map_err(|timeout_err| ErrorCode::Timeout(timeout_err.to_string()))?,
            None => rx.recv().map_err(ErrorCode::from_std_error)?,
        };
        Ok(reply)
    }
pub fn block_on < F > ( & self , f : F , timeout : Option < Duration > ) -> Result < F :: Output > where F : Future + Send + ' static , F :: Output : Send + ' static , { let ( tx , rx ) = channel ( ) ; let _jh = self . spawn ( async move { let r = f . await ; let _ = tx . send ( r ) ; } ) ; let reply = match timeout { Some ( to ) => rx . recv_timeout ( to ) . map_err ( | timeout_err | ErrorCode :: Timeout ( timeout_err . to_string ( ) ) ) ? , None => rx . recv ( ) . map_err ( ErrorCode :: from_std_error ) ? , } ; Ok ( reply ) }
Poor man's runtime::block_on
This mainly used for make async function to sync.
Poor man ' s runtime :: block_on This mainly used for make async function to sync .
&self
f
F
timeout
Option<Duration>
&self
f
F
timeout
Option<Duration>