pub struct Tx<T> { /* private fields */ }Expand description
A single producer (sender) that works in a blocking context.
Additional methods in ChannelShared can be accessed through Deref.
NOTE: Tx is not Clone or Sync.
If you need concurrent access, use MTx instead.
Tx has a Send marker and can be moved to other threads.
The following code is OK:
use crossfire::*;
let (tx, rx) = spsc::bounded_blocking::<usize>(100);
std::thread::spawn(move || {
let _ = tx.send(1);
});
drop(rx);Because Tx does not have a Sync marker, using Arc<Tx> will lose the Send marker.
For your safety, the following code should not compile:
use crossfire::*;
use std::sync::Arc;
let (tx, rx) = spsc::bounded_blocking::<usize>(100);
let tx = Arc::new(tx);
std::thread::spawn(move || {
let _ = tx.send(1);
});
drop(rx);Implementations§
Source§impl<T: Send + 'static> Tx<T>
impl<T: Send + 'static> Tx<T>
Sourcepub fn send(&self, item: T) -> Result<(), SendError<T>>
pub fn send(&self, item: T) -> Result<(), SendError<T>>
Sends a message. This method will block until the message is sent or the channel is closed.
Returns Ok(()) on success.
Returns Err(SendError) if the receiver has been dropped.
Sourcepub fn try_send(&self, item: T) -> Result<(), TrySendError<T>>
pub fn try_send(&self, item: T) -> Result<(), TrySendError<T>>
Attempts to send a message without blocking.
Returns Ok(()) when successful.
Returns Err(TrySendError::Full) if the channel is full.
Returns Err(TrySendError::Disconnected) if the receiver has been dropped.
Sourcepub fn send_timeout(
&self,
item: T,
timeout: Duration,
) -> Result<(), SendTimeoutError<T>>
pub fn send_timeout( &self, item: T, timeout: Duration, ) -> Result<(), SendTimeoutError<T>>
Sends a message with a timeout. Will block when channel is full.
The behavior is atomic: the message is either sent successfully or returned on error.
Returns Ok(()) when successful.
Returns Err(SendTimeoutError::Timeout) if the operation timed out.
Returns Err(SendTimeoutError::Disconnected) if the receiver has been dropped.