Struct AppRuntime
pub struct AppRuntime { /* private fields */ }Expand description
The process-wide app runtime: a current-thread tokio runtime driven by a dedicated thread.
One thread is enough for an app: its async work is network and IPC
waiting, not computation. CPU-bound work goes to crate::cpu() and
blocking calls to AppRuntime::spawn_blocking, so neither stalls the
other tasks.
The runtime starts on first use and lives as long as the process.
Implementations§
§impl AppRuntime
impl AppRuntime
pub const fn handle(&self) -> &Handle
pub const fn handle(&self) -> &Handle
The runtime’s handle, for APIs that take one or need a runtime
context (handle().enter()) to construct I/O resources.
pub fn is_runtime_thread(&self) -> bool
pub fn is_runtime_thread(&self) -> bool
Whether the calling thread is the one driving this runtime.
pub fn spawn<F>(&self, future: F) -> JoinHandle<<F as Future>::Output> ⓘ
pub fn spawn<F>(&self, future: F) -> JoinHandle<<F as Future>::Output> ⓘ
Run future on the runtime thread. Returns immediately; the
caller never polls it.
pub fn spawn_then<F, D>(&self, future: F, deliver: D) -> JoinHandle<()> ⓘ
pub fn spawn_then<F, D>(&self, future: F, deliver: D) -> JoinHandle<()> ⓘ
Run future on the runtime thread, then hand its output to
deliver there. deliver should only publish — complete a
LatestRequest, send on a channel — so the runtime thread is free
for the next task. This is the UI handoff: the UI thread spawns, and
deliver wakes the event loop with the result.
pub fn spawn_pinned<M, F>(&self, make: M) -> JoinHandle<<F as Future>::Output> ⓘ
pub fn spawn_pinned<M, F>(&self, make: M) -> JoinHandle<<F as Future>::Output> ⓘ
Run the future make builds, where the future may hold values that
stay on one thread (a browser page’s storage handles, where that is
the target): natively it is built and driven on one thread of the
blocking pool, with the runtime’s drivers.
pub fn spawn_blocking<F, R>(&self, call: F) -> JoinHandle<R> ⓘ
pub fn spawn_blocking<F, R>(&self, call: F) -> JoinHandle<R> ⓘ
Run a blocking call on the runtime’s bounded blocking pool.
pub fn block_on<F>(&self, future: F) -> Result<<F as Future>::Output, Error>where
F: Future,
pub fn block_on<F>(&self, future: F) -> Result<<F as Future>::Output, Error>where
F: Future,
Wait on future from a synchronous thread.
For threads that own a blocking API (a git transport callback, a
decoder loop, a synchronous library entry point) and need one async
result. The caller polls future itself — so it may borrow — while
the runtime thread drives its sockets and timers and runs anything it
spawns. No runtime is built per call.
§Errors
Error::UiThread on a UI thread, Error::InsideRuntime from a
runtime context, where waiting would stall the tasks that thread is
meant to run.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AppRuntime
impl RefUnwindSafe for AppRuntime
impl Send for AppRuntime
impl Sync for AppRuntime
impl Unpin for AppRuntime
impl UnsafeUnpin for AppRuntime
impl UnwindSafe for AppRuntime
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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more