pub struct RuntimeInbox<A> { /* private fields */ }Expand description
UI-thread consumer for a bounded runtime mailbox.
The receiver and target RuntimeHandle remain UI-local. Dropping the
inbox closes all sender clones and drops buffered actions.
§Examples
use std::num::NonZeroUsize;
use ailloli_ui_runtime::app::RuntimeInbox;
let (_sender, inbox) = RuntimeInbox::<()>::channel(NonZeroUsize::new(2).unwrap());
assert_eq!(inbox.stats().drained, 0);Implementations§
Source§impl<A> RuntimeInbox<A>
Provides the operations defined for RuntimeInbox<A>.
impl<A> RuntimeInbox<A>
Provides the operations defined for RuntimeInbox<A>.
Sourcepub fn channel(capacity: NonZeroUsize) -> (RuntimeSender<A>, Self)
pub fn channel(capacity: NonZeroUsize) -> (RuntimeSender<A>, Self)
Creates a bounded mailbox with exact nonzero message capacity.
No wake callback is initially installed; messages sent before late installation retain a pending wake requirement.
§Examples
use std::num::NonZeroUsize;
use ailloli_ui_runtime::app::{RuntimeHandle, RuntimeInbox};
let (sender, mut inbox) = RuntimeInbox::channel(NonZeroUsize::new(2).unwrap());
sender.dispatch(8).unwrap();
let runtime = RuntimeHandle::new();
assert_eq!(inbox.drain(&runtime).unwrap().dispatched_actions, 1);
assert_eq!(runtime.take_actions(), [8]);Sourcepub fn install_wake(&self, wake: Arc<dyn UiWake>) -> Result<(), UiWakeError>
pub fn install_wake(&self, wake: Arc<dyn UiWake>) -> Result<(), UiWakeError>
Installs or replaces the host wake callback. Messages queued before this call cause the newly installed callback to run immediately.
Callback invocation is synchronous and outside the wake mutex. On error, the callback remains installed and the wake remains retryable.
§Errors
Returns the callback’s UiWakeError when delivering an already
outstanding notification fails.
§Examples
use std::num::NonZeroUsize; use std::sync::Arc;
use ailloli_ui_runtime::app::{RuntimeInbox, UiWake, UiWakeError};
struct Wake; impl UiWake for Wake { fn wake(&self)->Result<(),UiWakeError>{Ok(())} }
let (_sender, inbox) = RuntimeInbox::<()>::channel(NonZeroUsize::new(1).unwrap());
assert!(inbox.install_wake(Arc::new(Wake)).is_ok());Sourcepub fn detach_wake(&self)
pub fn detach_wake(&self)
Detaches the current host callback while retaining any outstanding wake requirement for the next installed callback.
§Examples
use std::num::NonZeroUsize;
use ailloli_ui_runtime::app::RuntimeInbox;
let (_sender, inbox) = RuntimeInbox::<()>::channel(NonZeroUsize::new(1).unwrap());
inbox.detach_wake();
assert_eq!(inbox.stats().wake_calls, 0);Sourcepub fn stats(&self) -> RuntimeInboxStats
pub fn stats(&self) -> RuntimeInboxStats
Returns a non-resetting shared instrumentation snapshot.
§Examples
use std::num::NonZeroUsize;
use ailloli_ui_runtime::app::RuntimeInbox;
let (_sender, inbox) = RuntimeInbox::<()>::channel(NonZeroUsize::new(1).unwrap());
assert_eq!(inbox.stats(), Default::default());Sourcepub fn drain(
&mut self,
runtime: &RuntimeHandle<A>,
) -> Result<RuntimeDrain, UiWakeError>
pub fn drain( &mut self, runtime: &RuntimeHandle<A>, ) -> Result<RuntimeDrain, UiWakeError>
Applies at most RUNTIME_INBOX_DRAIN_BUDGET messages to the UI-local
runtime. When work remains, another host wake is requested.
Actions preserve FIFO order. Redraw pending markers are cleared as their
messages are applied. At the budget, one extra message is prefetched to
set remaining; it stays counted in depth until the next drain.
§Errors
Returns a wake error only when a remainder needs another host signal. By then the first 256 messages have already been applied and their result is not returned, so hosts should treat this failure as requiring prompt retry/fatal recovery rather than repeat the messages.
§Examples
use std::num::NonZeroUsize;
use ailloli_ui_runtime::app::{RuntimeHandle, RuntimeInbox};
let (sender, mut inbox) = RuntimeInbox::channel(NonZeroUsize::new(2).unwrap());
sender.dispatch("one").unwrap(); sender.request_redraw().unwrap();
let runtime = RuntimeHandle::new();
let result = inbox.drain(&runtime).unwrap();
assert_eq!((result.drained_messages, result.dispatched_actions, result.redraw_all), (2, 1, true));