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
//! # Basic
//!
//! The simplest possible taskvisor program: **one task, one run, one exit.**
//! Start here to understand the minimal wiring.
//!
//! ## What this shows
//!
//! - `TaskFn::arc` wraps a closure into an `Arc<dyn Task>` (a `TaskRef`).
//! - `TaskSpec::once(task)` creates a one-shot spec (`RestartPolicy::Never`).
//! - `Supervisor::run(specs)` blocks until all tasks finish or Ctrl+C is pressed.
//!
//! The `CancellationToken` parameter is unused here because the task completes instantly.
//!
//! For long-running tasks that **must react to shut down**, see `worker.rs`.
//!
//! ## Runtime flavor
//!
//! We use `current_thread` here because a single-threaded runtime is enough for examples and tests.
//!
//! *It can be used with `#[tokio::main]` (defaults to multi-thread): taskvisor works with both.*
//!
//! ## Run
//!
//! ```bash
//! cargo run --example basic
//! ```
//!
//! ## Next
//!
//! | Example | What it adds |
//! |------------------------------|------------------------------------------|
//! | [`worker.rs`](worker.rs) | Long-running task with graceful shutdown |
//! | [`periodic.rs`](periodic.rs) | Cron-like repeated execution |
use *;
async