⏰ schedule.rs 🚀
✨ A lightweight Rust library for scheduling operations across multiple time scales! ✨
👥 Who This Is For
This library is perfect for developers who need:
- 🎯 Simple, predictable scheduling with absolute time intervals
- 🧩 Lightweight scheduling without complex calendar-based rules
- ⚙️ Precise control over execution timing in systems programming
- 🔧 Efficient scheduling in resource-constrained environments
By design, we focus on absolute time durations (every 5 seconds, every 10 minutes) and deliberately avoid calendar-based scheduling (every Thursday, first day of month). This keeps the API clean, predictable, and easy to reason about for systems programming tasks.
🎯 Features
- ⚡ Multiple tick frequencies (milliseconds to minutes)
- 🕰️ Configurable time sources for ultimate flexibility
- 🔄 Compound durations (e.g., 10 minutes plus 30 seconds)
- 📝 Named schedules with intuitive fluent builder API
- 🔗 Direct callback references and event emission
- 💾 Easy serialization and state persistence
- 🔄 Both synchronous AND asynchronous execution support
🚀 Usage
// Create a scheduler with default settings
let mut scheduler = new;
// Or create with custom configuration
let config = SchedulerConfig ;
let mut scheduler = with_config;
// Register a callback handler (traditional way)
;
scheduler.register_callback;
// Or register a callback using the helper function (much simpler!)
scheduler.register_callback;
// Create a schedule with the registered handler
scheduler.every
.with_name
.with_callback_id
.build;
// For simple cases, use the convenience method
scheduler.every
.with_name
.execute;
// Start the scheduler
scheduler.start;
// You can manage schedules directly:
let all_schedules = scheduler.get_all_schedules;
scheduler.remove_schedule;
scheduler.clear_schedules;
// Later, freeze the state
let state = scheduler.freeze;
let serialized = to_string.unwrap;
// Restore (requires re-registering handlers)
let state: SchedulerState = from_str.unwrap;
let mut restored = restore;
restored.register_callback;
restored.start;
⚡ Async Support
For asynchronous operation with Tokio (requires the async feature):
// Enable the feature in Cargo.toml:
// [dependencies]
// schedule_rs = { version = "0.1.0", features = ["async"] }
// Create an async scheduler with default settings
let mut scheduler = new;
// Or create with custom configuration
let config = SchedulerConfig ;
let mut scheduler = with_config;
// Register an async handler
scheduler.register_async_handler;
// Create and start schedules as with the sync scheduler
scheduler.every
.with_name
.with_callback_id
.build;
scheduler.start;
📦 Installation
Add to your Cargo.toml:
[]
= "0.1.0"
# For async support:
= { = "0.1.0", = ["async"] }
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🎉 Contribute
Contributions are welcome! Feel free to open issues and submit PRs to make schedule.rs even better!