Struct async_slot::sync::Sender
[−]
[src]
pub struct Sender<T> { /* fields omitted */ }
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.
Methods
impl<T> Sender<T>
[src]
fn swap(&self, value: T) -> Result<Option<T>, SendError<T>>
[src]
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.
fn poll_cancel(&mut self) -> Poll<(), ()>
[src]
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.
fn is_canceled(&self) -> bool
[src]
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
impl<T: Debug> Debug for Sender<T>
[src]
impl<T> Sink for Sender<T>
[src]
type SinkItem = T
The type of value that the sink accepts.
type SinkError = SendError<T>
The type of value produced by the sink when an error occurs.
fn start_send(&mut self, item: T) -> StartSend<T, SendError<T>>
[src]
Begin the process of sending a value to the sink. Read more
fn poll_complete(&mut self) -> Poll<(), Self::SinkError>
[src]
Flush all output from this sink, if necessary. Read more
fn close(&mut self) -> Poll<(), Self::SinkError>
[src]
A method to indicate that no more values will ever be pushed into this sink. Read more
fn wait(self) -> Wait<Self>
[src]
Creates a new object which will produce a synchronous sink. Read more
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>,
[src]
F: FnMut(U) -> Fut,
Fut: IntoFuture<Item = Self::SinkItem>,
<Fut as IntoFuture>::Error: From<Self::SinkError>,
Composes a function in front of the sink. Read more
fn with_flat_map<U, F, St>(self, f: F) -> WithFlatMap<Self, U, F, St> where
F: FnMut(U) -> St,
St: Stream<Item = Self::SinkItem, Error = Self::SinkError>,
[src]
F: FnMut(U) -> St,
St: Stream<Item = Self::SinkItem, Error = Self::SinkError>,
Composes a function in front of the sink. Read more
fn sink_map_err<F, E>(self, f: F) -> SinkMapErr<Self, F> where
F: FnOnce(Self::SinkError) -> E,
[src]
F: FnOnce(Self::SinkError) -> E,
Transforms the error returned by the sink.
fn sink_from_err<E>(self) -> SinkFromErr<Self, E> where
E: From<Self::SinkError>,
[src]
E: From<Self::SinkError>,
Map this sink's error to any error implementing From
for this sink's Error
, returning a new sink. Read more
fn buffer(self, amt: usize) -> Buffer<Self>
[src]
Adds a fixed-size buffer to the current sink. Read more
fn flush(self) -> Flush<Self>
[src]
A future that completes when the sink has finished processing all pending requests. Read more
fn send(self, item: Self::SinkItem) -> Send<Self>
[src]
A future that completes after the given item has been fully processed into the sink, including flushing. Read more
fn send_all<S>(self, stream: S) -> SendAll<Self, S> where
S: Stream<Item = Self::SinkItem>,
Self::SinkError: From<<S as Stream>::Error>,
[src]
S: Stream<Item = Self::SinkItem>,
Self::SinkError: From<<S as Stream>::Error>,
A future that completes after the given stream has been fully processed into the sink, including flushing. Read more