Expand description
Main thread executor for async operations.
This module provides utilities for running futures on the main thread, which is required for UI operations on many platforms. The executor integrates with the native event loop to process both async tasks and platform events.
§Example
#[cfg(target_arch = "wasm32")] {
}
use app_window::test_support::doctest_main;
use some_executor::task::{Configuration, Task};
doctest_main(|| {
Task::without_notifications(
"doctest".to_string(),
Configuration::default(),
async {
use app_window::executor;
async fn my_async_function() -> i32 { 42 }
// Run an async function on the main thread
let result = executor::on_main_thread_async(
"ex".to_owned(),
my_async_function()
).await;
assert_eq!(result, 42);
},
).spawn_static_current();
});A mini-executor for running futures on the main thread.
This module provides an executor specifically designed to run futures on the application’s main thread while cooperating with the native event loop. This is essential for platforms that require certain operations (like UI updates) to happen on the main thread.
The executor uses a task queue that’s processed whenever the main thread’s event loop allows it, ensuring that futures can yield control back to the native event loop for smooth operation.
§Thread Safety
All futures submitted to this executor will run on the main thread. The executor provides two main entry points:
on_main_thread_async: Can be called from any thread to run a future on the main threadalready_on_main_thread_submit: Must be called from the main thread
§Integration with some_executor
When the some_executor feature is enabled, this executor can be wrapped with
crate::some_executor::MainThreadExecutor to provide a some_executor::SomeExecutor
implementation.
Functions§
- already_
on_ main_ thread_ submit - Submits a future to the main thread executor for execution.
- on_
main_ thread_ async - Runs the specified future on the main thread and returns its result.