fn drain( &self ) {
        let _enter = enter().expect( "EventLoopExecutor is already draining" );

        if !self.is_draining.replace( true ) {
            let maybe_realloc_capacity = self.estimate_realloc_capacity();

            // Poll all the pending tasks
            loop {
                let mut inner = self.inner.borrow_mut();

                match inner.queue.pop_front() {
                    Some( task ) => {
                        // This is necessary because the polled task might queue more tasks
                        drop( inner );
                        Task::poll( task );
                    },
                    None => {
                        // We decided to reclaim some space
                        if let Some( ( old_capacity, realloc_capacity ) ) = maybe_realloc_capacity {
                            inner.queue = VecDeque::with_capacity( realloc_capacity );

                            let new_capacity = inner.queue.capacity();

                            // This makes sure that we are actually shrinking the capacity
                            assert!( new_capacity < old_capacity );

                            // This is necessary because the estimate_realloc_capacity method
                            // relies upon the behavior of the VecDeque's capacity
                            assert!( new_capacity < realloc_capacity * 2 );
                        }

                        self.is_draining.set( false );

                        break;
                    },
                }
            }
        }
    }
// Poll the queue until it is empty
Poll the queue until it is empty
Poll the queue until it is empty
fn drain( &self ) {
        let _enter = enter().expect( "EventLoopExecutor is already draining" );
        if !self.is_draining.replace( true ) {
            let maybe_realloc_capacity = self.estimate_realloc_capacity();
            // Poll all the pending tasks
            loop {
                let mut inner = self.inner.borrow_mut();
                match inner.queue.pop_front() {
                    Some( task ) => {
                        // This is necessary because the polled task might queue more tasks
                        drop( inner );
                        Task::poll( task );
                    },
                    None => {
                        // We decided to reclaim some space
                        if let Some( ( old_capacity, realloc_capacity ) ) = maybe_realloc_capacity {
                            inner.queue = VecDeque::with_capacity( realloc_capacity );
                            let new_capacity = inner.queue.capacity();
                            // This makes sure that we are actually shrinking the capacity
                            assert!( new_capacity < old_capacity );
                            // This is necessary because the estimate_realloc_capacity method
                            // relies upon the behavior of the VecDeque's capacity
                            assert!( new_capacity < realloc_capacity * 2 );
                        }
                        self.is_draining.set( false );
                        break;
                    },
                }
            }
        }
    }
fn drain ( & self ) { let _enter = enter ( ) . expect ( " " ) ; if ! self . is_draining . replace ( true ) { let maybe_realloc_capacity = self . estimate_realloc_capacity ( ) ; // Poll all the pending tasks loop { let mut inner = self . inner . borrow_mut ( ) ; match inner . queue . pop_front ( ) { Some ( task ) => { // This is necessary because the polled task might queue more tasks drop ( inner ) ; Task :: poll ( task ) ; } , None => { // We decided to reclaim some space if let Some ( ( old_capacity , realloc_capacity ) ) = maybe_realloc_capacity { inner . queue = VecDeque :: with_capacity ( realloc_capacity ) ; let new_capacity = inner . queue . capacity ( ) ; // This makes sure that we are actually shrinking the capacity assert ! ( new_capacity old_capacity ) ; // This is necessary because the estimate_realloc_capacity method // relies upon the behavior of the VecDeque's capacity assert ! ( new_capacity realloc_capacity 2 ) ; } self . is_draining . set ( false ) ; break ; } , } } } }
Poll the queue until it is empty
Poll the queue until it is empty
&self
&self