unsafe fn try_send(
        &mut self,
        wait_node: &mut ListNode<SendWaitQueueEntry<T>>,
        cx: &mut Context<'_>,
    ) -> (Poll<()>, Option<T>) {
        match wait_node.state {
            SendPollState::Unregistered => {
                if self.is_closed {
                    let value = wait_node.value.take();
                    return (Poll::Ready(()), value);
                }

                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);

                    // Wakeup the oldest receive waiter
                    wakeup_last_receive_waiter(&mut self.receive_waiters);
                    return (Poll::Pending, None);
                }
                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);

                    // Wakeup the oldest receive waiter
                    wakeup_last_receive_waiter(&mut self.receive_waiters);

                    (Poll::Ready(()), None)
                }
            },
            SendPollState::Registered => {
                // Since the channel wakes up all waiters and moves their states to unregistered
                // there can't be space available in the channel.
                (Poll::Pending, None)
            },
            SendPollState::SendComplete => {
                // The transfer is complete, and the sender has already been removed from the
                // list of pending senders
                (Poll::Ready(()), None)
            },
        }
    }
/// 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.
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.
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 .
unsafe fn try_send(
        &mut self,
        wait_node: &mut ListNode<SendWaitQueueEntry<T>>,
        cx: &mut Context<'_>,
    ) -> (Poll<()>, Option<T>) {
        match wait_node.state {
            SendPollState::Unregistered => {
                if self.is_closed {
                    let value = wait_node.value.take();
                    return (Poll::Ready(()), value);
                }
                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);
                    // Wakeup the oldest receive waiter
                    wakeup_last_receive_waiter(&mut self.receive_waiters);
                    return (Poll::Pending, None);
                }
                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);
                    // Wakeup the oldest receive waiter
                    wakeup_last_receive_waiter(&mut self.receive_waiters);
                    (Poll::Ready(()), None)
                }
            },
            SendPollState::Registered => {
                // Since the channel wakes up all waiters and moves their states to unregistered
                // there can't be space available in the channel.
                (Poll::Pending, None)
            },
            SendPollState::SendComplete => {
                // The transfer is complete, and the sender has already been removed from the
                // list of pending senders
                (Poll::Ready(()), None)
            },
        }
    }
unsafe fn try_send ( & mut self , wait_node : & mut ListNode < SendWaitQueueEntry < T > > , cx : & mut Context < ' _ > , ) -> ( Poll < ( ) > , Option < T > ) { match wait_node . state { SendPollState :: Unregistered => { if self . is_closed { let value = wait_node . value . take ( ) ; return ( Poll :: Ready ( ( ) ) , value ) ; } 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 ) ; // Wakeup the oldest receive waiter wakeup_last_receive_waiter ( & mut self . receive_waiters ) ; return ( Poll :: Pending , None ) ; } else { // Otherwise copy the value directly into the channel let value = wait_node . value . take ( ) . expect ( " " ) ; self . buffer . push ( value ) ; // Wakeup the oldest receive waiter wakeup_last_receive_waiter ( & mut self . receive_waiters ) ; ( Poll :: Ready ( ( ) ) , None ) } } , SendPollState :: Registered => { // Since the channel wakes up all waiters and moves their states to unregistered // there can't be space available in the channel. ( Poll :: Pending , None ) } , SendPollState :: SendComplete => { // The transfer is complete, and the sender has already been removed from the // list of pending senders ( Poll :: Ready ( ( ) ) , 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<'_>
&mut self
wait_node
&mut ListNode<SendWaitQueueEntry<T>>
cx
&mut Context<'_>