mirror of
https://github.com/lexmount/moli.git
synced 2026-10-06 00:00:56 +00:00
Adopt completed image buffers, protect readers with snapshots, and park encoded bytes into one disk extent with a reusable backup. Keep resident and parked registries separate, expose owner-driven deadlines and force parking, and synchronize notifications with a short-lock waiting flag. Include lifecycle, concurrency, scheduling, and failure regressions with documentation and runnable examples.
31 lines
1.2 KiB
Rust
31 lines
1.2 KiB
Rust
//! Drive one parking deadline with a custom policy and synthetic image bytes.
|
|
//!
|
|
//! Run with `cargo run -p moli-parkable-image --example deadline`.
|
|
//!
|
|
//! This single-threaded, one-shot wait is not a concurrent scheduler.
|
|
//! Concurrent owners must also react to new_with_schedule_wakeup() notifications.
|
|
|
|
use std::time::{Duration, Instant};
|
|
|
|
use moli_disk_pool::DiskPool;
|
|
use moli_parkable_image::{ParkableImageManager, ParkableImagePolicy};
|
|
|
|
fn main() -> std::io::Result<()> {
|
|
let policy = ParkableImagePolicy {
|
|
parking_delay: Duration::from_millis(10),
|
|
..ParkableImagePolicy::default()
|
|
};
|
|
let manager = ParkableImageManager::new(Some(DiskPool::new(None)?), policy);
|
|
let image = manager.from_frozen_bytes(vec![3; 4096]);
|
|
|
|
let deadline = manager.next_parking_deadline().expect("image is eligible");
|
|
std::thread::sleep(deadline.saturating_duration_since(Instant::now()));
|
|
manager.park_images();
|
|
|
|
assert_eq!(image.retained_memory_bytes(), 0);
|
|
assert_eq!(manager.diagnostics().parked_count, 1);
|
|
assert!(manager.next_parking_deadline().is_none());
|
|
println!("Parked the image at its deadline; no further deadline is scheduled.");
|
|
Ok(())
|
|
}
|