Struct sync::comm::SyncSender[src]

pub struct SyncSender<T> {
    // some fields omitted
}

The sending-half of Rust's synchronous channel type. This half can only be owned by one task, but it can be cloned to send to other tasks.

Methods

impl<T: Send> SyncSender<T>

fn send(&self, t: T)

Sends a value on this synchronous channel.

This function will block until space in the internal buffer becomes available or a receiver is available to hand off the message to.

Note that a successful send does not guarantee that the receiver will ever see the data if there is a buffer on this channel. Messages may be enqueued in the internal buffer for the receiver to receive at a later time. If the buffer size is 0, however, it can be guaranteed that the receiver has indeed received the data if this function returns success.

Failure

Similarly to Sender::send, this function will fail if the corresponding Receiver for this channel has disconnected. This behavior is used to propagate failure among tasks.

If failure is not desired, you can achieve the same semantics with the SyncSender::send_opt method which will not fail if the receiver disconnects.

fn send_opt(&self, t: T) -> Result<(), T>

Send a value on a channel, returning it back if the receiver disconnected

This method will block to send the value t on the channel, but if the value could not be sent due to the receiver disconnecting, the value is returned back to the callee. This function is similar to try_send, except that it will block if the channel is currently full.

Failure

This function cannot fail.

fn try_send(&self, t: T) -> Result<(), TrySendError<T>>

Attempts to send a value on this channel without blocking.

This method differs from send_opt by returning immediately if the channel's buffer is full or no receiver is waiting to acquire some data. Compared with send_opt, this function has two failure cases instead of one (one for disconnection, one for a full buffer).

See SyncSender::send for notes about guarantees of whether the receiver has received the data or not if this function is successful.

Failure

This function cannot fail

Trait Implementations

impl<T: Send> Clone for SyncSender<T>

fn clone(&self) -> SyncSender<T>

fn clone_from(&mut self, source: &Self)

impl<T: Send> Drop for SyncSender<T>

fn drop(&mut self)