Expand description
§Task abstractions.
This module contains the types used to define work and describe how it runs.
| Type | Role |
|---|---|
Task | Trait for user work |
TaskFn | Closure-based Task |
TaskRef | Shared task handle: Arc<dyn Task> |
TaskSpec | Run config: restart, backoff, timeout, retry limit |
BoxTaskFuture | Future returned by Task::spawn |
§Creating A Task
- Use
TaskFnfor most tasks. Pass a name and an async closure. - Use
impl Taskwhen 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§
- Task
Context - Context passed to a
Taskfor one attempt. - TaskFn
- Closure-based
Taskimplementation. - Task
Spec - Describes how a
Taskshould run.
Traits§
- Task
- Async unit of work managed by a
Supervisor.
Type Aliases§
- BoxTask
Future - Boxed, pinned,
Sendfuture: the return type ofTask::spawn. - TaskRef
- Shared task handle:
Arc<dyn Task>.