AsyncFallibleExt

Trait AsyncFallibleExt 

Source
pub trait AsyncFallibleExt<T> {
    // Required methods
    fn send_lossy(&mut self, msg: T) -> impl Future<Output = bool> + Send;
    fn try_send_lossy(&mut self, msg: T) -> bool;
    fn request<R, F>(
        &mut self,
        make_msg: F,
    ) -> impl Future<Output = Option<R>> + Send
       where R: Send,
             F: FnOnce(Sender<R>) -> T + Send;
    fn request_or<R, F>(
        &mut self,
        make_msg: F,
        default: R,
    ) -> impl Future<Output = R> + Send
       where R: Send,
             F: FnOnce(Sender<R>) -> T + Send;
    fn request_or_default<R, F>(
        &mut self,
        make_msg: F,
    ) -> impl Future<Output = R> + Send
       where R: Default + Send,
             F: FnOnce(Sender<R>) -> T + Send;
}
Expand description

Extension trait for bounded channel operations that may fail due to disconnection.

Similar to FallibleExt but for bounded channels where send operations are async.

Required Methods§

Source

fn send_lossy(&mut self, msg: T) -> impl Future<Output = bool> + Send

Send a message asynchronously, returning true if successful.

Use this for fire-and-forget messages where the receiver may have been dropped during shutdown. The return value can be ignored if the caller doesn’t need to know whether the send succeeded.

Source

fn try_send_lossy(&mut self, msg: T) -> bool

Try to send a message without blocking, returning true if successful.

Use this for fire-and-forget messages where you don’t want to wait if the channel is full. Returns false if the channel is full or disconnected.

Source

fn request<R, F>( &mut self, make_msg: F, ) -> impl Future<Output = Option<R>> + Send
where R: Send, F: FnOnce(Sender<R>) -> T + Send,

Send a request message containing a oneshot responder and await the response.

Returns None if:

  • The receiver has been dropped (send fails)
  • The responder is dropped without sending (receive fails)
Source

fn request_or<R, F>( &mut self, make_msg: F, default: R, ) -> impl Future<Output = R> + Send
where R: Send, F: FnOnce(Sender<R>) -> T + Send,

Send a request and return the provided default on failure.

Source

fn request_or_default<R, F>( &mut self, make_msg: F, ) -> impl Future<Output = R> + Send
where R: Default + Send, F: FnOnce(Sender<R>) -> T + Send,

Send a request and return R::default() on failure.

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.

Implementations on Foreign Types§

Source§

impl<T: Send> AsyncFallibleExt<T> for Sender<T>

Source§

async fn send_lossy(&mut self, msg: T) -> bool

Source§

fn try_send_lossy(&mut self, msg: T) -> bool

Source§

async fn request<R, F>(&mut self, make_msg: F) -> Option<R>
where R: Send, F: FnOnce(Sender<R>) -> T + Send,

Source§

async fn request_or<R, F>(&mut self, make_msg: F, default: R) -> R
where R: Send, F: FnOnce(Sender<R>) -> T + Send,

Source§

async fn request_or_default<R, F>(&mut self, make_msg: F) -> R
where R: Default + Send, F: FnOnce(Sender<R>) -> T + Send,

Implementors§