pub struct Task { /* private fields */ }Expand description
A unit of deferred work.
Tasks encapsulate a closure to be executed later by the scheduler. Each task has a unique ID, priority, and execution state.
§Example
use reovim_kernel::api::v1::*;
// Create a high-priority task with a name
let mut task = Task::with_priority(Priority::HIGH, || println!("Hello!"))
.with_name("greeting");
assert_eq!(task.state(), TaskState::Pending);
assert_eq!(task.priority(), Priority::HIGH);
// Execute the task
let result = task.execute();
assert!(result.is_ok());
assert_eq!(task.state(), TaskState::Completed);Implementations§
Source§impl Task
impl Task
Sourcepub fn with_priority<F>(priority: Priority, work: F) -> Self
pub fn with_priority<F>(priority: Priority, work: F) -> Self
Create a task with specific priority.
Sourcepub const fn is_executable(&self) -> bool
pub const fn is_executable(&self) -> bool
Check if the task can still be executed.
Sourcepub fn execute(&mut self) -> Result<(), &'static str>
pub fn execute(&mut self) -> Result<(), &'static str>
Execute the task.
Consumes the work closure and transitions state to Completed.
§Errors
Returns an error if:
- Task has already been executed
- Task was cancelled (work is None)
Sourcepub fn mark_failed(&mut self)
pub fn mark_failed(&mut self)
Mark the task as failed.
Used by the executor when a panic is caught during execution.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Task
impl !RefUnwindSafe for Task
impl Send for Task
impl !Sync for Task
impl Unpin for Task
impl UnsafeUnpin for Task
impl !UnwindSafe for Task
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more