pub async fn blocking_run<F, T, FT>(
        &self,
        future: F,
        state: ThreadState,
        deadline: Duration,
        cancel_token: Option<Receiver<()>>,
    ) -> ZxResult<T>
    where
        F: Future<Output = FT> + Unpin,
        FT: IntoResult<T>,
    {
        let (old_state, killed) = {
            let mut inner = self.inner.lock();
            if inner.state() == ThreadState::Dying {
                return Err(ZxError::STOP);
            }
            let (sender, receiver) = channel();
            inner.killer = Some(sender);
            let old_state = inner.state;
            inner.change_state(state, &self.base);
            (old_state, receiver)
        };
        let ret = if let Some(cancel_token) = cancel_token {
            select_biased! {
                ret = future.fuse() => ret.into_result(),
                _ = killed.fuse() => Err(ZxError::STOP),
                _ = kernel_hal::thread::sleep_until(deadline).fuse() => Err(ZxError::TIMED_OUT),
                _ = cancel_token.fuse() => Err(ZxError::CANCELED),
            }
        } else {
            select_biased! {
                ret = future.fuse() => ret.into_result(),
                _ = killed.fuse() => Err(ZxError::STOP),
                _ = kernel_hal::thread::sleep_until(deadline).fuse() => Err(ZxError::TIMED_OUT),
            }
        };
        let mut inner = self.inner.lock();
        inner.killer = None;
        if inner.state() == ThreadState::Dying {
            return ret;
        }
        assert_eq!(inner.state, state);
        inner.change_state(old_state, &self.base);
        ret
    }
/// Run async future and change state while blocking.
Run async future and change state while blocking.
Run async future and change state while blocking .
pub async fn blocking_run<F, T, FT>(
        &self,
        future: F,
        state: ThreadState,
        deadline: Duration,
        cancel_token: Option<Receiver<()>>,
    ) -> ZxResult<T>
    where
        F: Future<Output = FT> + Unpin,
        FT: IntoResult<T>,
    {
        let (old_state, killed) = {
            let mut inner = self.inner.lock();
            if inner.state() == ThreadState::Dying {
                return Err(ZxError::STOP);
            }
            let (sender, receiver) = channel();
            inner.killer = Some(sender);
            let old_state = inner.state;
            inner.change_state(state, &self.base);
            (old_state, receiver)
        };
        let ret = if let Some(cancel_token) = cancel_token {
            select_biased! {
                ret = future.fuse() => ret.into_result(),
                _ = killed.fuse() => Err(ZxError::STOP),
                _ = kernel_hal::thread::sleep_until(deadline).fuse() => Err(ZxError::TIMED_OUT),
                _ = cancel_token.fuse() => Err(ZxError::CANCELED),
            }
        } else {
            select_biased! {
                ret = future.fuse() => ret.into_result(),
                _ = killed.fuse() => Err(ZxError::STOP),
                _ = kernel_hal::thread::sleep_until(deadline).fuse() => Err(ZxError::TIMED_OUT),
            }
        };
        let mut inner = self.inner.lock();
        inner.killer = None;
        if inner.state() == ThreadState::Dying {
            return ret;
        }
        assert_eq!(inner.state, state);
        inner.change_state(old_state, &self.base);
        ret
    }
pub async fn blocking_run < F , T , FT > ( & self , future : F , state : ThreadState , deadline : Duration , cancel_token : Option < Receiver < ( ) > > , ) -> ZxResult < T > where F : Future < Output = FT > + Unpin , FT : IntoResult < T > , { let ( old_state , killed ) = { let mut inner = self . inner . lock ( ) ; if inner . state ( ) == ThreadState :: Dying { return Err ( ZxError :: STOP ) ; } let ( sender , receiver ) = channel ( ) ; inner . killer = Some ( sender ) ; let old_state = inner . state ; inner . change_state ( state , & self . base ) ; ( old_state , receiver ) } ; let ret = if let Some ( cancel_token ) = cancel_token { select_biased ! { ret future fuse ( ) ret into_result ( ) killed fuse ( ) Err ( ZxError STOP ) kernel_hal thread sleep_until ( deadline ) fuse ( ) Err ( ZxError TIMED_OUT ) cancel_token fuse ( ) Err ( ZxError CANCELED ) } } else { select_biased ! { ret future fuse ( ) ret into_result ( ) killed fuse ( ) Err ( ZxError STOP ) kernel_hal thread sleep_until ( deadline ) fuse ( ) Err ( ZxError TIMED_OUT ) } } ; let mut inner = self . inner . lock ( ) ; inner . killer = None ; if inner . state ( ) == ThreadState :: Dying { return ret ; } assert_eq ! ( inner state state ) ; inner . change_state ( old_state , & self . base ) ; ret }
Run async future and change state while blocking.
Run async future and change state while blocking .
&self
future
F
state
ThreadState
deadline
Duration
cancel_token
Option<Receiver<()>>
&self
future
F
state
ThreadState
deadline
Duration
cancel_token
Option<Receiver<()>>