Skip to main content

Task

Trait Task 

Source
pub trait Task: Send + Sync {
    // Required methods
    fn id(&self) -> &str;
    fn execute<'life0, 'async_trait>(
        &'life0 self,
        ctx: Arc<Context>,
    ) -> Pin<Box<dyn Future<Output = Result<TaskOutput, TaskError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn dependencies(&self) -> Vec<String> { ... }
    fn priority(&self) -> u8 { ... }
}
Expand description

A unit of work in the DAG.

Implementations must be Send + Sync because tasks are shared across worker threads (Arc<dyn Task>) and executed concurrently. The default Task::dependencies and Task::priority make leaf, normal-priority tasks the zero-boilerplate case.

Required Methods§

Source

fn id(&self) -> &str

Stable, unique identifier for this task within a DAG.

Source

fn execute<'life0, 'async_trait>( &'life0 self, ctx: Arc<Context>, ) -> Pin<Box<dyn Future<Output = Result<TaskOutput, TaskError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Execute the task.

The returned future is run on the executor’s worker pool. Implementations should periodically check Context::is_cancelled for long-running work.

Provided Methods§

Source

fn dependencies(&self) -> Vec<String>

Ids of tasks that must complete successfully before this one runs.

Source

fn priority(&self) -> u8

Scheduling priority; higher values are scheduled first among ready tasks.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§