pub fn block_on_poll<'s, T>(
    mut poll: impl FnMut(&mut Context<'_>) -> Poll<T>,
    timeout: impl Into<Expiry>,
) -> Poll<T> {
    let timeout = timeout.into();
    with_listener(|guard, waker| {
        let mut cx = Context::from_waker(waker);
        let mut repeat = 0usize;
        loop {
            let result = poll(&mut cx);
            if result.is_ready() {
                break result;
            }
            match guard.park(timeout).unwrap() {
                ParkResult::Skipped => {
                    repeat += 1;
                    if repeat >= 5 {
                        // seem to be effectively in a spin loop, back off polling
                        thread::yield_now();
                    }
                }
                ParkResult::Unparked => {
                    repeat = 0;
                }
                ParkResult::TimedOut => break result,
            }
        }
    })
}
/// Block the current thread on the result of a poll function, with an optional timeout.
/// A [`None`] value is returned if the timeout is reached.
Block the current thread on the result of a poll function, with an optional timeout.
A [`None`] value is returned if the timeout is reached.
Block the current thread on the result of a poll function with an optional timeout . A [ ` None ` ] value is returned if the timeout is reached .
pub fn block_on_poll<'s, T>(
    mut poll: impl FnMut(&mut Context<'_>) -> Poll<T>,
    timeout: impl Into<Expiry>,
) -> Poll<T> {
    let timeout = timeout.into();
    with_listener(|guard, waker| {
        let mut cx = Context::from_waker(waker);
        let mut repeat = 0usize;
        loop {
            let result = poll(&mut cx);
            if result.is_ready() {
                break result;
            }
            match guard.park(timeout).unwrap() {
                ParkResult::Skipped => {
                    repeat += 1;
                    if repeat >= 5 {
                        // seem to be effectively in a spin loop, back off polling
                        thread::yield_now();
                    }
                }
                ParkResult::Unparked => {
                    repeat = 0;
                }
                ParkResult::TimedOut => break result,
            }
        }
    })
}
pub fn block_on_poll < ' s , T > ( mut poll : impl FnMut ( & mut Context < ' _ > ) -> Poll < T > , timeout : impl Into < Expiry > , ) -> Poll < T > { let timeout = timeout . into ( ) ; with_listener ( | guard , waker | { let mut cx = Context :: from_waker ( waker ) ; let mut repeat = 0usize ; loop { let result = poll ( & mut cx ) ; if result . is_ready ( ) { break result ; } match guard . park ( timeout ) . unwrap ( ) { ParkResult :: Skipped => { repeat += 1 ; if repeat >= 5 { // seem to be effectively in a spin loop, back off polling thread :: yield_now ( ) ; } } ParkResult :: Unparked => { repeat = 0 ; } ParkResult :: TimedOut => break result , } } } ) }
Block the current thread on the result of a poll function, with an optional timeout.
Block the current thread on the result of a poll function with an optional timeout .
poll
impl FnMut(&mut Context<'_>) -> Poll<T>
timeout
impl Into<Expiry>
poll
impl FnMut(&mut Context<'_>) -> Poll<T>
timeout
impl Into<Expiry>