#[non_exhaustive]pub enum Priority {
Default,
Background,
UserInitiated,
UserInteractive,
Utility,
}Expand description
Task execution priority levels for controlling scheduler behavior.
These priority levels map to platform-native scheduling priorities, allowing fine-grained control over task execution order and resource allocation.
§Platform notes
- Apple (macOS/iOS/Catalyst) and wasm/web backends are ready to use with no extra setup.
- Android requires calling
register_android_main_threadon the real UI thread before anyspawn_main/spawn_main_localusage, so the executor can dispatch tasks back to the platform main looper. - Polyfill backend (enabled via the
polyfillfeature on unsupported targets) needs you to create a dedicated thread and callpolyfill::executor::start_main_executorthere to simulate a main thread before usingspawn_main/spawn_local.
§Choosing an executor
NativeExecutor is the global, work-stealing executor and has no
main-thread affinity, so it is always available.
NativeMainExecutor dispatches to the platform main thread and only exists
where such a thread does, which is why it is constructed through an
Option rather than failing at the first spawn.
If your program owns an event loop — winit, GTK/glib, a frame pump — do not
use NativeMainExecutor. Implement LocalExecutor over that loop so
tasks run on the thread that owns your windows and graphics resources.
polyfill::executor::start_main_executor would otherwise declare an
unrelated thread “main” and dispatch your UI work to the wrong one.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Default
Standard priority level for most application tasks.
This is the default priority that provides balanced execution suitable for general-purpose async operations.
Background
Lower priority for background tasks and non-critical operations.
Background tasks yield CPU time to higher-priority tasks and are ideal for operations like cleanup, logging, or data processing that don’t require immediate completion.
UserInitiated
Higher priority for user-initiated tasks that require prompt execution. This priority is suitable for tasks that directly impact user experience, such as responding to user input or updating the UI.
UserInteractive
Highest priority for tasks that require immediate attention to maintain application responsiveness. This priority should be reserved for critical operations that must complete as soon as possible, such as rendering UI updates or handling real-time data.
Utility
Lowest priority for tasks that can be deferred until the system is idle. This priority is suitable for maintenance tasks, prefetching data, or other operations that do not need to run immediately and can wait until the system is less busy.