AsyncTxTrait

Trait AsyncTxTrait 

Source
pub trait AsyncTxTrait<T: Unpin + Send + 'static>:
    Send
    + 'static
    + Debug
    + Display
    + AsRef<ChannelShared<T>>
    + Into<AsyncSink<T>> {
    // Required methods
    fn try_send(&self, item: T) -> Result<(), TrySendError<T>>;
    fn clone_to_vec(self, count: usize) -> Vec<Self>
       where Self: Sized;
    fn send<'a>(&'a self, item: T) -> SendFuture<'a, T> ;
    fn send_timeout<'a>(
        &'a self,
        item: T,
        duration: Duration,
    ) -> SendTimeoutFuture<'a, T, ()> ;
    fn send_with_timer<'a, F, R>(
        &'a self,
        item: T,
        fut: F,
    ) -> SendTimeoutFuture<'a, T, R> 
       where F: Future<Output = R> + 'static;

    // Provided methods
    fn len(&self) -> usize { ... }
    fn capacity(&self) -> Option<usize> { ... }
    fn is_empty(&self) -> bool { ... }
    fn is_full(&self) -> bool { ... }
    fn is_disconnected(&self) -> bool { ... }
}
Expand description

For writing generic code with MAsyncTx & AsyncTx

Required Methods§

Source

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

Try to send message, non-blocking

Returns Ok(()) when successful.

Returns Err(TrySendError::Full) on channel full for bounded channel.

Returns Err(TrySendError::Disconnected) when all Rx dropped.

Source

fn clone_to_vec(self, count: usize) -> Vec<Self>
where Self: Sized,

Source

fn send<'a>(&'a self, item: T) -> SendFuture<'a, T>

Send message. Will await when channel is full.

Returns Ok(()) on successful.

Returns Err(SendError) when all Rx is dropped.

Source

fn send_timeout<'a>( &'a self, item: T, duration: Duration, ) -> SendTimeoutFuture<'a, T, ()>

Available on crate features tokio or async_std only.

Waits for a message to be sent into the channel, but only for a limited time. Will await when channel is full.

The behavior is atomic, either message sent successfully or returned on error.

Returns Ok(()) when successful.

Returns Err(SendTimeoutError::Timeout) when the operation timed out.

Returns Err(SendTimeoutError::Disconnected) when all Rx dropped.

Source

fn send_with_timer<'a, F, R>( &'a self, item: T, fut: F, ) -> SendTimeoutFuture<'a, T, R>
where F: Future<Output = R> + 'static,

Sends a message with a custom timer function. Will await when channel is full.

The behavior is atomic: the message is either sent successfully or returned with error.

Returns Ok(()) when successful.

Returns Err(SendTimeoutError::Timeout) if the operation timed out. The error contains the message that failed to be sent.

Returns Err(SendTimeoutError::Disconnected) if the receiver has been dropped. The error contains the message that failed to be sent.

§Argument:
  • fut: The sleep function. It’s possible to wrap this function with cancelable handle, you can control when to stop polling. the return value of fut is ignore. We add generic R just in order to support smol::Timer

Provided Methods§

Source

fn len(&self) -> usize

The number of messages in the channel at the moment

Source

fn capacity(&self) -> Option<usize>

The capacity of the channel, return None for unbounded channel.

Source

fn is_empty(&self) -> bool

Whether channel is empty at the moment

Source

fn is_full(&self) -> bool

Whether the channel is full at the moment

Source

fn is_disconnected(&self) -> bool

Return true if the other side has closed

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T: Unpin + Send + 'static> AsyncTxTrait<T> for AsyncTx<T>

Source§

impl<T: Unpin + Send + 'static> AsyncTxTrait<T> for MAsyncTx<T>