pub fn spawn_with_priority<Fut>(
future: Fut,
priority: Priority,
) -> Task<Fut::Output>
Expand description
Creates a new task with the specified execution priority.
This allows fine-grained control over task scheduling, enabling background tasks to yield to higher-priority operations.
§Arguments
future
- The future to execute asynchronouslypriority
- The scheduling priority for this task
§Returns
A Task
handle that can be awaited to retrieve the result
§Examples
use native_executor::{spawn_with_priority, Priority};
// High-priority task for time-sensitive operations
let urgent = spawn_with_priority(async {
// Your time-sensitive work here
42
}, Priority::Default);
// Background task that won't interfere with UI responsiveness
let cleanup = spawn_with_priority(async {
// Your background work here
"done"
}, Priority::Background);