pub fn spawn_main<Fut>(future: Fut) -> Task<Fut::Output>
Expand description
Creates a new task that executes on the main thread.
This function schedules a Send
future to run specifically on the main thread.
This is useful for operations that must happen on the main thread, such as
UI updates or accessing main-thread-only APIs.
§Arguments
future
- The Send future to execute on the main thread
§Returns
A Task
handle that can be awaited to retrieve the result
§Examples
use native_executor::spawn_main;
let task = spawn_main(async {
// This runs on the main thread
println!("Running on main thread");
"done"
});