pub struct Sender<T> { /* private fields */ }Expand description
Slot is very similar to unbounded channel but only stores last value sent
I.e. if you want to send some value between from producer to a consumer and if consumer is slow it should skip old values, the slot is a structure for the task. The transmission end of a channel which is used to send values
If the receiver is not fast enough only the last value is preserved and other ones are discarded.
Implementations§
Source§impl<T> Sender<T>
impl<T> Sender<T>
Sourcepub fn swap(&self, value: T) -> Result<Option<T>, SendError<T>>
pub fn swap(&self, value: T) -> Result<Option<T>, SendError<T>>
Sets the new new value of the stream and notifies the consumer if any
This function will store the value provided as the current value for
this channel, replacing any previous value that may have been there. If
the receiver may still be able to receive this message, then Ok is
returned with the previous value that was in this channel.
If Ok(Some) is returned then this value overwrote a previous value,
and the value was never received by the receiver. If Ok(None) is
returned, then no previous value was found and the value is queued up
to be received by the receiver.
§Errors
This function will return an Err if the receiver has gone away and
it’s impossible to send this value to the receiver. The error returned
retains ownership of the value provided and can be extracted, if
necessary.
Sourcepub fn poll_cancel(&mut self) -> Poll<(), ()>
pub fn poll_cancel(&mut self) -> Poll<(), ()>
Polls this Sender half to detect whether the Receiver this has
paired with has gone away.
This function can be used to learn about when the Receiver (consumer)
half has gone away and nothing will be able to receive a message sent
from send (or swap).
If Ready is returned then it means that the Receiver has disappeared
and the result this Sender would otherwise produce should no longer
be produced.
If NotReady is returned then the Receiver is still alive and may be
able to receive a message if sent. The current task, however, is
scheduled to receive a notification if the corresponding Receiver goes
away.
§Panics
Like Future::poll, this function will panic if it’s not called from
within the context of a task. In other words, this should only ever be
called from inside another future.
If you’re calling this function from a context that does not have a
task, then you can use the is_canceled API instead.
Sourcepub fn is_canceled(&self) -> bool
pub fn is_canceled(&self) -> bool
Tests to see whether this Sender’s corresponding Receiver
has gone away.
This function can be used to learn about when the Receiver (consumer)
half has gone away and nothing will be able to receive a message sent
from send.
Note that this function is intended to not be used in the context of a
future. If you’re implementing a future you probably want to call the
poll_cancel function which will block the current task if the
cancellation hasn’t happened yet. This can be useful when working on a
non-futures related thread, though, which would otherwise panic if
poll_cancel were called.
Trait Implementations§
Source§impl<T> Sink for Sender<T>
impl<T> Sink for Sender<T>
Source§fn start_send(&mut self, item: T) -> StartSend<T, SendError<T>>
fn start_send(&mut self, item: T) -> StartSend<T, SendError<T>>
Source§fn poll_complete(&mut self) -> Poll<(), Self::SinkError>
fn poll_complete(&mut self) -> Poll<(), Self::SinkError>
Source§fn close(&mut self) -> Poll<(), Self::SinkError>
fn close(&mut self) -> Poll<(), Self::SinkError>
Source§fn wait(self) -> Wait<Self>where
Self: Sized,
fn wait(self) -> Wait<Self>where
Self: Sized,
Source§fn with<U, F, Fut>(self, f: F) -> With<Self, U, F, Fut>where
F: FnMut(U) -> Fut,
Fut: IntoFuture<Item = Self::SinkItem>,
<Fut as IntoFuture>::Error: From<Self::SinkError>,
Self: Sized,
fn with<U, F, Fut>(self, f: F) -> With<Self, U, F, Fut>where
F: FnMut(U) -> Fut,
Fut: IntoFuture<Item = Self::SinkItem>,
<Fut as IntoFuture>::Error: From<Self::SinkError>,
Self: Sized,
Source§fn with_flat_map<U, F, St>(self, f: F) -> WithFlatMap<Self, U, F, St>
fn with_flat_map<U, F, St>(self, f: F) -> WithFlatMap<Self, U, F, St>
Source§fn sink_map_err<F, E>(self, f: F) -> SinkMapErr<Self, F>
fn sink_map_err<F, E>(self, f: F) -> SinkMapErr<Self, F>
Source§fn sink_from_err<E>(self) -> SinkFromErr<Self, E>
fn sink_from_err<E>(self) -> SinkFromErr<Self, E>
From for this sink’s
Error, returning a new sink. Read more