Struct std::comm::Chan
pub struct Chan<T> {
// some fields omitted
}The sending-half of Rust's channel type. This half can only be owned by one task
Fields
Methods
impl<T: Send> Chan<T>
fn new() -> (Port<T>, Chan<T>)
Creates a new port/channel pair. All data send on the channel returned
will become available on the port as well. See the documentation of
Port and Chan to see what's possible with them.
fn send(&self, t: T)
Sends a value along this channel to be received by the corresponding port.
Rust channels are infinitely buffered so this method will never block.
Failure
This function will fail if the other end of the channel has hung up. This means that if the corresponding port has fallen out of scope, this function will trigger a fail message saying that a message is being sent on a closed channel.
Note that if this function does not fail, it does not mean that the data will be successfully received. All sends are placed into a queue, so it is possible for a send to succeed (the other end is alive), but then the other end could immediately disconnect.
The purpose of this functionality is to propagate failure among tasks.
If failure is not desired, then consider using the try_send method
fn try_send(&self, t: T) -> bool
Attempts to send a value on this channel, returning whether it was successfully sent.
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 port has already been deallocated. Note that a return
value of false means that the data will never be received, but a
return value of true does not mean that the data will be received.
It is possible for the corresponding port to hang up immediately after
this function returns true.
Like send, this method will never block. If the failure of send cannot
be tolerated, then this method should be used instead.
fn try_send_deferred(&self, t: T) -> bool
This function will not stick around for very long. The purpose of this function is to guarantee that no rescheduling is performed.