1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//! # Task abstractions.
//!
//! | Type | Role |
//! |-------------------|---------------------------------------------|
//! | [`TaskSpec`] | Execution config: restart, backoff, timeout |
//! | [`TaskRef`] | Shared handle - `Arc<dyn Task>` |
//! | [`TaskFn`] | Closure-based [`Task`] (most common) |
//! | [`Task`] | **Trait**; async, cancelable unit of work |
//! | [`BoxTaskFuture`] | Return type of [`Task::spawn`] |
//!
//! ## Flow
//!
//! There are two ways to create a task:
//!
//! **[`TaskFn`]** - pass a name and an async closure.
//!
//! The closure is called on every start and restart, producing a fresh future each time.
//! No struct, no trait impl - just a function. Suitable for the majority of use cases.
//!
//! See examples on [`TaskFn`].
//!
//! **`impl Task`** - define your own struct and implement the [`Task`] trait manually.
//! Gives full control over [`name()`](Task::name) and [`spawn()`](Task::spawn).
//! Use when you need custom initialization, dependency injection, or behavior that a closure cannot express.
//!
//! See example on [`Task`].
//!
//! ## Schema
//!
//! Both paths produce a [`TaskRef`] (`Arc<dyn Task>`), which is then wrapped
//! in a [`TaskSpec`] to configure restart policy, backoff, and timeout.
//!
//! ```text
//! TaskFn::arc(name, closure) ─┐
//! ├──► TaskRef ──► TaskSpec ──► Supervisor
//! struct MyTask impl Task ─┘
//! ```
//!
//! ## Quick start
//!
//! ```rust
//! use taskvisor::{TaskFn, TaskRef, TaskSpec, TaskError};
//! use tokio_util::sync::CancellationToken;
//!
//! let task: TaskRef = TaskFn::arc("worker", |ctx: CancellationToken| async move {
//! // ... do work, observe ctx.cancelled() ...
//! Ok::<(), TaskError>(())
//! });
//!
//! let spec = TaskSpec::once(task); // run once
//! // TaskSpec::restartable(task); // restart on failure
//! // TaskSpec::with_defaults(task, &cfg); // inherit from config
//! ```
pub use ;
pub use r#