pub trait EventContextAsyncExt {
// Required methods
fn spawn_local(
&mut self,
future: impl Future<Output = ()> + 'static,
) -> TaskHandle;
fn spawn_local_with<R: 'static>(
&mut self,
future: impl Future<Output = R> + 'static,
on_complete: impl FnOnce(R, &mut EventContext<'_>) + 'static,
) -> TaskHandle;
}Expand description
Spawn async work on the main-thread executor from inside an event handler.
Brought into scope with use teksilo_async::EventContextAsyncExt; (or via
the teksilo prelude when the async feature is on).
Required Methods§
Sourcefn spawn_local(
&mut self,
future: impl Future<Output = ()> + 'static,
) -> TaskHandle
fn spawn_local( &mut self, future: impl Future<Output = ()> + 'static, ) -> TaskHandle
Spawn a !Send future. It runs on the UI thread and may capture and
mutate Signals and other Rc handles directly on resume. Drop the
returned TaskHandle to cancel, or call .detach() to fire-and-forget.
Sourcefn spawn_local_with<R: 'static>(
&mut self,
future: impl Future<Output = R> + 'static,
on_complete: impl FnOnce(R, &mut EventContext<'_>) + 'static,
) -> TaskHandle
fn spawn_local_with<R: 'static>( &mut self, future: impl Future<Output = R> + 'static, on_complete: impl FnOnce(R, &mut EventContext<'_>) + 'static, ) -> TaskHandle
Spawn a future and deliver its result to on_complete with a fresh
EventContext bound to this window’s tree — the supported way to run
a one-shot ambient op (open_window, send_intent, …) once the work
finishes. The future body itself runs handle-only.
§Panics
Panics if called outside a window context (there is no window to bind
the completion to). Use spawn_local from such
sites and drive UI updates through Signals.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".