/// Tries to read the value from the channel.
/// If the value isn't available yet, the ChannelReceiveFuture gets added to the
/// wait queue at the channel, and will be signalled once ready.
/// This function is only safe as long as the `wait_node`s address is guaranteed
/// to be stable until it gets removed from the queue.
Tries to read the value from the channel.
If the value isn't available yet, the ChannelReceiveFuture gets added to the
wait queue at the channel, and will be signalled once ready.
This function is only safe as long as the `wait_node`s address is guaranteed
to be stable until it gets removed from the queue.
Tries to read the value from the channel . If the value isn ' t available yet the ChannelReceiveFuture gets added to the wait queue at the channel and will be signalled once ready . This function is only safe as long as the ` wait_node ` s address is guaranteed to be stable until it gets removed from the queue .
unsafe fn receive_or_register(
        &mut self,
        wait_node: &mut ListNode<RecvWaitQueueEntry>,
        cx: &mut Context<'_>,
    ) -> Poll<Option<(T, Option<Waker>)>> {
        match wait_node.state {
            RecvPollState::Unregistered | RecvPollState::Notified => {
                wait_node.state = RecvPollState::Unregistered;
                match self.try_receive() {
                    Ok(val) => Poll::Ready(Some(val)),
                    Err(TryReceiveError::Closed) => Poll::Ready(None),
                    Err(TryReceiveError::Empty) => {
                        // Added the task to the wait queue
                        wait_node.task = Some(cx.waker().clone());
                        wait_node.state = RecvPollState::Registered;
                        self.receive_waiters.add_front(wait_node);
                        Poll::Pending
                    }
                }
            }
            RecvPollState::Registered => {
                // Since the channel wakes up all waiters and moves their states
                // to unregistered there can't be any value in the channel in
                // this state. However the caller might have passed a different `Waker`.
                // In this case we need to update it.
                update_waker_ref(&mut wait_node.task, cx);
                Poll::Pending
            }
        }
    }
unsafe fn receive_or_register ( & mut self , wait_node : & mut ListNode < RecvWaitQueueEntry > , cx : & mut Context < ' _ > , ) -> Poll < Option < ( T , Option < Waker > ) > > { match wait_node . state { RecvPollState :: Unregistered | RecvPollState :: Notified => { wait_node . state = RecvPollState :: Unregistered ; match self . try_receive ( ) { Ok ( val ) => Poll :: Ready ( Some ( val ) ) , Err ( TryReceiveError :: Closed ) => Poll :: Ready ( None ) , Err ( TryReceiveError :: Empty ) => { // Added the task to the wait queue wait_node . task = Some ( cx . waker ( ) . clone ( ) ) ; wait_node . state = RecvPollState :: Registered ; self . receive_waiters . add_front ( wait_node ) ; Poll :: Pending } } } RecvPollState :: Registered => { // Since the channel wakes up all waiters and moves their states // to unregistered there can't be any value in the channel in // this state. However the caller might have passed a different `Waker`. // In this case we need to update it. update_waker_ref ( & mut wait_node . task , cx ) ; Poll :: Pending } } }
Tries to read the value from the channel.
Tries to read the value from the channel .
&mut self
wait_node
&mut ListNode<RecvWaitQueueEntry>
cx
&mut Context<'_>