pub struct UiSender<T> { /* private fields */ }Expand description
Thread-safe producer for a bounded, wakeable UI mailbox.
Clones share the same channel and counters. UiSender<T> is Send + Sync
when T permits it; ordering follows the standard MPSC channel across all
producers.
§Examples
use std::num::NonZeroUsize;
use ailloli_ui_runtime::app::UiInbox;
let (sender, _inbox) = UiInbox::<u8>::channel(NonZeroUsize::new(2).unwrap());
assert_eq!(sender.stats().enqueued, 0);Implementations§
Source§impl<T> UiSender<T>
Provides the operations defined for UiSender<T>.
impl<T> UiSender<T>
Provides the operations defined for UiSender<T>.
Sourcepub fn send(&self, message: T) -> Result<(), UiSendError>
pub fn send(&self, message: T) -> Result<(), UiSendError>
Attempts a nonblocking enqueue, then coalesces a host wake.
On Full or Closed, ownership of message is lost with the error and
the queue is unchanged. EnqueuedButWakeFailed means the message remains
queued. With no callback installed, the send succeeds and records a wake
requirement for late installation.
§Errors
Returns UiSendError::Full or UiSendError::Closed without
enqueueing. UiSendError::EnqueuedButWakeFailed means enqueueing
succeeded but the installed wake callback failed.
§Examples
use std::num::NonZeroUsize;
use ailloli_ui_runtime::app::{UiInbox, UiSendError};
let (sender, _inbox) = UiInbox::channel(NonZeroUsize::new(1).unwrap());
sender.send(1).unwrap();
assert_eq!(sender.send(2), Err(UiSendError::Full));Sourcepub fn send_blocking(&self, message: T) -> Result<(), UiSendError>
pub fn send_blocking(&self, message: T) -> Result<(), UiSendError>
Enqueues with bounded backpressure, then wakes the UI host.
Worker threads may use this when dropping a response would violate
their protocol. UI threads should prefer Self::send so they never
block on a full mailbox.
This can block indefinitely while the receiver remains alive but does not drain a full queue. A wake failure still leaves the message queued.
§Errors
Returns UiSendError::Closed if the receiver disappears before the
enqueue, or UiSendError::EnqueuedButWakeFailed after a successful
enqueue whose host wake failed.
§Examples
use std::num::NonZeroUsize;
use ailloli_ui_runtime::app::UiInbox;
let (sender, mut inbox) = UiInbox::channel(NonZeroUsize::new(1).unwrap());
sender.send_blocking("ready").unwrap();
assert_eq!(inbox.drain(NonZeroUsize::new(1).unwrap()).unwrap().messages, ["ready"]);Sourcepub fn request_wake(&self) -> Result<(), UiSendError>
pub fn request_wake(&self) -> Result<(), UiSendError>
Retries an outstanding wake without adding another message.
A signaled/in-flight wake coalesces to success. With no callback this
records NeedsWake and also returns success.
§Errors
Returns UiSendError::EnqueuedButWakeFailed when the installed wake
callback reports a closed or temporarily unavailable target.
§Examples
use std::num::NonZeroUsize;
use ailloli_ui_runtime::app::UiInbox;
let (sender, _inbox) = UiInbox::<()>::channel(NonZeroUsize::new(1).unwrap());
assert!(sender.request_wake().is_ok());
assert_eq!(sender.stats().enqueued, 0);Sourcepub fn stats(&self) -> UiInboxStats
pub fn stats(&self) -> UiInboxStats
Returns a non-resetting shared statistics snapshot.
§Examples
use std::num::NonZeroUsize;
use ailloli_ui_runtime::app::UiInbox;
let (sender, _inbox) = UiInbox::channel(NonZeroUsize::new(1).unwrap());
sender.send(1).unwrap();
assert_eq!(sender.stats().current_depth, 1);Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for UiSender<T>
impl<T> RefUnwindSafe for UiSender<T>
impl<T> Send for UiSender<T>where
T: Send,
impl<T> Sync for UiSender<T>where
T: Send,
impl<T> Unpin for UiSender<T>
impl<T> UnwindSafe for UiSender<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<A> IntoClickAction<A> for Awhere
A: Clone + 'static,
impl<A> IntoClickAction<A> for Awhere
A: Clone + 'static,
Source§fn into_click_action(self) -> ClickAction<A>
fn into_click_action(self) -> ClickAction<A>
Implements the into_click_action helper used by this module.