progress-token
A Rust library for hierarchical progress tracking with support for cancellation, status updates, and nested operations.
Features
- 🌳 Hierarchical Progress: Create trees of operations with weighted progress tracking
- 📢 Status Updates: Track and propagate status messages through the operation hierarchy
- ⏸️ Cancellation: Built-in support for cancelling operations and their children
- 📊 Progress States: Support for both determinate (0.0-1.0) and indeterminate progress
- 🔄 Multiple Subscribers: Allow multiple parts of your application to monitor progress
- 🧮 Automatic Aggregation: Progress automatically calculated from weighted child tasks
Installation
Add this to your Cargo.toml
:
[]
= "0.1.0"
Quick Start
use ProgressToken;
async
Usage Examples
Basic Progress Tracking
let token = new;
// Update progress
token.progress;
token.status;
// Mark as complete when done
token.complete;
Status Updates
Status messages propagate through the hierarchy, with the most specific (deepest) status being reported:
let root = new;
let compress = child;
// Update status with more specific information
compress.status;
// Get full status hierarchy
let statuses = root.statuses;
assert_eq!;
Progress Subscription
let token = new;
let mut updates = token.subscribe;
spawn;
Cancellation
let token = new;
// In one part of your code
if error_condition
// In another part
if token.is_cancelled
Implementation Notes
- Progress values are automatically clamped to the range 0.0-1.0
- Child task weights should sum to 1.0 for accurate progress calculation
- Status updates and progress changes are broadcast to all subscribers
- Completed or cancelled tokens ignore further progress/status updates
- The broadcast channel has a reasonable buffer size to prevent lagging
License
This project is licensed under the MIT License - see the LICENSE.md file for details.