pub async fn on_main_thread_async<R: Send + 'static, F: Future<Output = R> + Send + 'static>(
debug_label: String,
future: F,
) -> RExpand description
Runs the specified future on the main thread and returns its result.
This function can be called from any thread. It submits the given future to the main thread executor and waits for its completion. While the future is executing, the main thread can still process other events, allowing for cooperative multitasking.
§Type Parameters
R- The return type of the future, must beSend + 'staticF- The future type, must beSend + 'staticand returnR
§Examples
// Call from any thread to compute on the main thread
let result = app_window::executor::on_main_thread_async("ex".to_owned(),async {
// This code runs on the main thread
// Perform computation that needs main thread access
2 + 2
}).await;
assert_eq!(result, 4);§Platform Behavior
On all supported platforms, this ensures the future runs on the thread that owns the native event loop, which is required for UI operations.