pub struct Sender<T: ?Sized> { /* private fields */ }
Expand description
The sending end of an established channel.
This type of sender is obtained when a channel has been fully established, either by
PendingSender::established
or by UnclaimedSender::claim
.
Implementations§
source§impl<T: ?Sized> Sender<T>
impl<T: ?Sized> Sender<T>
Returns the sender’s ChannelCookie
.
sourcepub fn client(&self) -> Option<&Handle>
pub fn client(&self) -> Option<&Handle>
Returns a handle to the client that was used to create the sender.
None
will be returned if the sender is closed.
sourcepub fn poll_send_ready(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<(), Error>>
pub fn poll_send_ready( &mut self, cx: &mut Context<'_>, ) -> Poll<Result<(), Error>>
Polls the channel for capacity to send at least 1 item.
sourcepub async fn send_ready(&mut self) -> Result<(), Error>
pub async fn send_ready(&mut self) -> Result<(), Error>
Waits until the channel has capacity to send at least 1 item.
sourcepub async fn close(&mut self) -> Result<(), Error>
pub async fn close(&mut self) -> Result<(), Error>
Closes the sender without consuming it.
The will cause the receiving end to receive None
after all other items have been
received.
§Examples
let (sender, receiver) = handle.create_channel_with_claimed_sender().await?;
let mut receiver = receiver.claim(16).await?;
let mut sender = sender.established().await?;
// Send a couple of items and then close the sender.
sender.send_item(&1).await?;
sender.send_item(&2).await?;
sender.send_item(&3).await?;
sender.close().await?;
// The receiver will receive all items followed by None.
assert_eq!(receiver.next_item().await, Ok(Some(1)));
assert_eq!(receiver.next_item().await, Ok(Some(2)));
assert_eq!(receiver.next_item().await, Ok(Some(3)));
assert_eq!(receiver.next_item().await, Ok(None));
sourcepub fn poll_closed(&mut self, cx: &mut Context<'_>) -> Poll<()>
pub fn poll_closed(&mut self, cx: &mut Context<'_>) -> Poll<()>
Polls whether the channel is closed.
source§impl<T: Serialize + ?Sized> Sender<T>
impl<T: Serialize + ?Sized> Sender<T>
sourcepub fn start_send_item(&mut self, item: &T) -> Result<(), Error>
pub fn start_send_item(&mut self, item: &T) -> Result<(), Error>
Sends an item on the channel.
This function panics if the channel doesn’t have any capacity left. You must call either
send_ready
or poll_send_ready
before to
ensure there is capacity.
Trait Implementations§
source§impl<T: Serialize + ?Sized> Sink<&T> for Sender<T>
impl<T: Serialize + ?Sized> Sink<&T> for Sender<T>
source§fn poll_ready(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>>
fn poll_ready( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>
Sink
to receive a value. Read moresource§fn start_send(self: Pin<&mut Self>, item: &T) -> Result<(), Self::Error>
fn start_send(self: Pin<&mut Self>, item: &T) -> Result<(), Self::Error>
poll_ready
which returned Poll::Ready(Ok(()))
. Read moresource§impl<T: Serialize> Sink<T> for Sender<T>
impl<T: Serialize> Sink<T> for Sender<T>
source§fn poll_ready(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>>
fn poll_ready( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>
Sink
to receive a value. Read moresource§fn start_send(self: Pin<&mut Self>, item: T) -> Result<(), Self::Error>
fn start_send(self: Pin<&mut Self>, item: T) -> Result<(), Self::Error>
poll_ready
which returned Poll::Ready(Ok(()))
. Read more