Expand description
Delayed task scheduling with a hierarchical timer wheel.
The default timer uses standard library threads and synchronization
primitives. Expired tasks are dispatched to an executor so task execution
does not block scheduler progress.
The scheduler advances time and dispatches expired tasks through
executor::Executor::try_execute. The default pool and optional runtime
adapters keep worker execution outside the scheduler thread. Custom
executors must return from try_execute immediately and return the original
task in executor::RejectedTask when they cannot accept work.
§Example
use std::sync::mpsc;
use std::time::Duration;
use timerwheel::Timer;
let timer = Timer::builder()
.tick(Duration::from_millis(1))
.bucket_count(64)
.build()?;
let (tx, rx) = mpsc::channel();
let timeout = timer.schedule(Duration::from_millis(5), move || {
tx.send("fired").expect("send succeeds");
})?;
assert_eq!(rx.recv_timeout(Duration::from_secs(1))?, "fired");
let _ = timeout;
timer.shutdown()?;
Re-exports§
pub use crate::error::Error;pub use crate::error::Result;pub use crate::policy::BackpressurePolicy;pub use crate::policy::ExpiredTaskPolicy;pub use crate::policy::RejectPolicy;pub use crate::timer::Timeout;pub use crate::timer::Timer;pub use crate::timer::TimerBuilder;pub use crate::timer::TimerMetrics;
Modules§
- error
- Error and result types returned by timerwheel APIs.
- executor
- Executor traits and the default bounded worker pool.
- policy
- Backpressure and rejection policies.
- prelude
- Common imports for applications that prefer a single glob import. Common imports for applications that prefer a single glob import.
- timer
- Timer, timeout, builder, and timer metric types.