/// Tries to send a value to the channel.
/// If the value isn't available yet, the ChannelSendFuture gets added to the
/// wait queue at the channel, and will be signalled once ready.
/// If the channels is already closed, the value to send is returned.
/// 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.
/// If sending the value succeeded, the `Waker` for a task which can receive
/// the value is returned.
Tries to send a value to the channel.
If the value isn't available yet, the ChannelSendFuture gets added to the
wait queue at the channel, and will be signalled once ready.
If the channels is already closed, the value to send is returned.
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.
If sending the value succeeded, the `Waker` for a task which can receive
the value is returned.
Tries to send a value to the channel . If the value isn ' t available yet the ChannelSendFuture gets added to the wait queue at the channel and will be signalled once ready . If the channels is already closed the value to send is returned . 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 . If sending the value succeeded the ` Waker ` for a task which can receive the value is returned .
unsafe fn send_or_register(
        &mut self,
        wait_node: &mut ListNode<SendWaitQueueEntry<T>>,
        cx: &mut Context<'_>,
    ) -> (Poll<()>, Option<T>, Option<Waker>) {
        match wait_node.state {
            SendPollState::Unregistered => {
                if self.is_closed {
                    let value = wait_node.value.take();
                    return (Poll::Ready(()), value, None);
                }
                if !self.buffer.can_push() {
                    // If the capacity is exhausted, register a waiter
                    wait_node.task = Some(cx.waker().clone());
                    wait_node.state = SendPollState::Registered;
                    self.send_waiters.add_front(wait_node);
                    // Return the oldest receive waiter
                    let waker =
                        return_oldest_receive_waiter(&mut self.receive_waiters);
                    return (Poll::Pending, None, waker);
                } else {
                    // Otherwise copy the value directly into the channel
                    let value = wait_node
                        .value
                        .take()
                        .expect("wait_node must contain value");
                    self.buffer.push(value);
                    // Return the oldest receive waiter
                    let waker =
                        return_oldest_receive_waiter(&mut self.receive_waiters);
                    (Poll::Ready(()), None, waker)
                }
            }
            SendPollState::Registered => {
                // Since the channel wakes up all waiters and moves their states
                // to unregistered there can't be space available in the channel.
                // 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, None, None)
            }
            SendPollState::SendComplete => {
                // The transfer is complete, and the sender has already been removed from the
                // list of pending senders
                (Poll::Ready(()), None, None)
            }
        }
    }
unsafe fn send_or_register ( & mut self , wait_node : & mut ListNode < SendWaitQueueEntry < T > > , cx : & mut Context < ' _ > , ) -> ( Poll < ( ) > , Option < T > , Option < Waker > ) { match wait_node . state { SendPollState :: Unregistered => { if self . is_closed { let value = wait_node . value . take ( ) ; return ( Poll :: Ready ( ( ) ) , value , None ) ; } if ! self . buffer . can_push ( ) { // If the capacity is exhausted, register a waiter wait_node . task = Some ( cx . waker ( ) . clone ( ) ) ; wait_node . state = SendPollState :: Registered ; self . send_waiters . add_front ( wait_node ) ; // Return the oldest receive waiter let waker = return_oldest_receive_waiter ( & mut self . receive_waiters ) ; return ( Poll :: Pending , None , waker ) ; } else { // Otherwise copy the value directly into the channel let value = wait_node . value . take ( ) . expect ( " " ) ; self . buffer . push ( value ) ; // Return the oldest receive waiter let waker = return_oldest_receive_waiter ( & mut self . receive_waiters ) ; ( Poll :: Ready ( ( ) ) , None , waker ) } } SendPollState :: Registered => { // Since the channel wakes up all waiters and moves their states // to unregistered there can't be space available in the channel. // 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 , None , None ) } SendPollState :: SendComplete => { // The transfer is complete, and the sender has already been removed from the // list of pending senders ( Poll :: Ready ( ( ) ) , None , None ) } } }
Tries to send a value to the channel.
Tries to send a value to the channel .
&mut self
wait_node
&mut ListNode<SendWaitQueueEntry<T>>
cx
&mut Context<'_>