Struct ksched::mpsc::Sender [−][src]
pub struct Sender<T>(_);
Expand description
The transmission end of a unbounded mpsc channel.
This value is created by the channel
function.
Implementations
impl<T> Sender<T>
[src]
impl<T> Sender<T>
[src]pub fn is_closed(&self) -> bool
[src]
pub fn is_closed(&self) -> bool
[src]Check whether the channel is closed.
A closed channel cannot be sent to.
Examples
use ksched::sync::mpsc; use ksched::task; let (tx, mut rx) = mpsc::channel::<usize>().unwrap(); assert_eq!(tx.is_closed(), false); rx.close(); assert_eq!(tx.is_closed(), true);
pub fn send(&self, value: T) -> Result<(), T>
[src]
pub fn send(&self, value: T) -> Result<(), T>
[src]Sends a value.
A successful send occurs when it is determined that the other end of the channel has not
hung up already. An unsuccessful send would be one where the corresponding receiver has
already been closed or allocation failed. Note that a return value of Err
means that the
data will never be received, but a return value of Ok
does not mean that the data will
be received. It is possible for the corresponding receiver to hang up immediately after
this function returns Ok
.
Errors
If the receive half of the channel is closed, either due to close
being called or the
Receiver
handle dropping, the function returns an error. Or if allocation fails during
create a message for sending, the function returns an error. The error includes the value
passed to send
.
Examples
In the following example, each call to send
will block until the previously sent value
was received.
use ksched::sync::mpsc; use ksched::task; let (tx, mut rx) = mpsc::channel().unwrap(); task::spawn(async move { for i in 0..10 { if let Err(_) = tx.send(i) { println!("receiver dropped"); return; } } }).unwrap(); while let Some(i) = rx.recv().await { println!("got = {}", i); }
Trait Implementations
Auto Trait Implementations
impl<T> !RefUnwindSafe for Sender<T>
impl<T> Send for Sender<T> where
T: Send,
T: Send,
impl<T> Sync for Sender<T> where
T: Send,
T: Send,
impl<T> Unpin for Sender<T>
impl<T> !UnwindSafe for Sender<T>
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more