Skip to main content

Module tasks

Module tasks 

Source
Expand description

§Task abstractions.

This module contains the types used to define work and describe how it runs.

TypeRole
TaskTrait for user work
TaskFnClosure-based Task
TaskRefShared task handle: Arc<dyn Task>
TaskSpecRun config: restart, backoff, timeout, retry limit
BoxTaskFutureFuture returned by Task::spawn

§Creating A Task

  • Use TaskFn for most tasks. Pass a name and an async closure.
  • Use impl Task when the task needs its own type or shared dependencies.

§Data Flow

Both paths create a TaskRef. Wrap it in a TaskSpec to choose restart policy, backoff, timeout, and retry limit.

TaskFn::arc(name, closure) ─┐
                            ├──► TaskRef ──► TaskSpec ──► Supervisor
impl Task                  ─┘

§Quick Start

use taskvisor::{TaskContext, TaskError, TaskFn, TaskRef, TaskSpec};

let task: TaskRef = TaskFn::arc("worker", |_ctx| async move {
    Ok(())
});

let once = TaskSpec::once(task.clone());
let restartable = TaskSpec::restartable(task.clone());

Use SupervisorConfig::task_spec when you want a task to inherit supervisor defaults.

Structs§

TaskContext
Context passed to a Task for one attempt.
TaskFn
Closure-based Task implementation.
TaskSpec
Describes how a Task should run.

Traits§

Task
Async unit of work managed by a Supervisor.

Type Aliases§

BoxTaskFuture
Boxed, pinned, Send future: the return type of Task::spawn.
TaskRef
Shared task handle: Arc<dyn Task>.